diff options
Diffstat (limited to '.emacs.d/lisp/markdown-mode.el')
| -rw-r--r-- | .emacs.d/lisp/markdown-mode.el | 95 |
1 files changed, 68 insertions, 27 deletions
diff --git a/.emacs.d/lisp/markdown-mode.el b/.emacs.d/lisp/markdown-mode.el index 671210e..77f9bf5 100644 --- a/.emacs.d/lisp/markdown-mode.el +++ b/.emacs.d/lisp/markdown-mode.el | |||
| @@ -187,12 +187,10 @@ fewer than six nested heading levels are used." | |||
| 187 | :safe 'natnump | 187 | :safe 'natnump |
| 188 | :package-version '(markdown-mode . "2.4")) | 188 | :package-version '(markdown-mode . "2.4")) |
| 189 | 189 | ||
| 190 | (defcustom markdown-asymmetric-header nil | 190 | (defcustom markdown-asymmetric-header t |
| 191 | "Determines if atx header style will be asymmetric. | 191 | "Determines if atx header style will be asymmetric. |
| 192 | Set to a non-nil value to use asymmetric header styling, placing | 192 | Set to a non-nil value to use asymmetric header styling, placing |
| 193 | header markup only at the beginning of the line. By default, | 193 | header markup only at the beginning of the line." |
| 194 | balanced markup will be inserted at the beginning and end of the | ||
| 195 | line around the header title." | ||
| 196 | :group 'markdown | 194 | :group 'markdown |
| 197 | :type 'boolean) | 195 | :type 'boolean) |
| 198 | 196 | ||
| @@ -2612,7 +2610,11 @@ Return the point at the end when a list item was found at the | |||
| 2612 | original point. If the point is not in a list item, do nothing." | 2610 | original point. If the point is not in a list item, do nothing." |
| 2613 | (let (indent) | 2611 | (let (indent) |
| 2614 | (forward-line) | 2612 | (forward-line) |
| 2615 | (setq indent (current-indentation)) | 2613 | ;; #904 consider a space indentation and tab indentation case |
| 2614 | (save-excursion | ||
| 2615 | (let ((pos (point))) | ||
| 2616 | (back-to-indentation) | ||
| 2617 | (setq indent (- (point) pos)))) | ||
| 2616 | (while | 2618 | (while |
| 2617 | (cond | 2619 | (cond |
| 2618 | ;; Stop at end of the buffer. | 2620 | ;; Stop at end of the buffer. |
| @@ -2902,7 +2904,8 @@ data. See `markdown-inline-code-at-point-p' for inline code." | |||
| 2902 | (defun markdown-heading-at-point (&optional pos) | 2904 | (defun markdown-heading-at-point (&optional pos) |
| 2903 | "Return non-nil if there is a heading at the POS. | 2905 | "Return non-nil if there is a heading at the POS. |
| 2904 | Set match data for `markdown-regex-header'." | 2906 | Set match data for `markdown-regex-header'." |
| 2905 | (let ((match-data (get-text-property (or pos (point)) 'markdown-heading))) | 2907 | (let* ((p (or pos (if (and (eolp) (>= (point) 2)) (1- (point)) (point)))) |
| 2908 | (match-data (get-text-property p 'markdown-heading))) | ||
| 2906 | (when match-data | 2909 | (when match-data |
| 2907 | (set-match-data match-data) | 2910 | (set-match-data match-data) |
| 2908 | t))) | 2911 | t))) |
| @@ -9321,6 +9324,37 @@ position." | |||
| 9321 | (require 'edit-indirect nil t) | 9324 | (require 'edit-indirect nil t) |
| 9322 | (defvar edit-indirect-guess-mode-function) | 9325 | (defvar edit-indirect-guess-mode-function) |
| 9323 | (defvar edit-indirect-after-commit-functions) | 9326 | (defvar edit-indirect-after-commit-functions) |
| 9327 | (defvar edit-indirect--overlay) | ||
| 9328 | (declare-function edit-indirect-commit "edit-indirect") | ||
| 9329 | (declare-function edit-indirect--commit "edit-indirect") | ||
| 9330 | |||
| 9331 | (defvar-local markdown--edit-indirect-committed-position nil) | ||
| 9332 | |||
| 9333 | (defun markdown--edit-indirect-save-committed-position () | ||
| 9334 | "Save where editing is committed in a local variable in the parent buffer." | ||
| 9335 | (if-let* ((parent-buffer (overlay-buffer edit-indirect--overlay)) | ||
| 9336 | ((with-current-buffer parent-buffer | ||
| 9337 | (derived-mode-p 'markdown-mode))) | ||
| 9338 | (pos (cons (line-number-at-pos) (current-column)))) | ||
| 9339 | (with-current-buffer parent-buffer | ||
| 9340 | (setq markdown--edit-indirect-committed-position pos)))) | ||
| 9341 | |||
| 9342 | (with-eval-after-load 'edit-indirect | ||
| 9343 | (advice-add #'edit-indirect--commit :after #'markdown--edit-indirect-save-committed-position)) | ||
| 9344 | |||
| 9345 | (defun markdown--edit-indirect-move-to-committed-position () | ||
| 9346 | "Move the point in the code block corresponding to the saved committed position." | ||
| 9347 | (when-let* ((pos markdown--edit-indirect-committed-position) | ||
| 9348 | (bounds (markdown-get-enclosing-fenced-block-construct)) | ||
| 9349 | (fence-begin (nth 0 bounds))) | ||
| 9350 | (goto-char fence-begin) | ||
| 9351 | (let ((block-indentation (current-indentation))) | ||
| 9352 | (forward-line (car pos)) | ||
| 9353 | (move-to-column (+ block-indentation (cdr pos))))) | ||
| 9354 | (setq markdown--edit-indirect-committed-position nil)) | ||
| 9355 | |||
| 9356 | (with-eval-after-load 'edit-indirect | ||
| 9357 | (advice-add #'edit-indirect-commit :after #'markdown--edit-indirect-move-to-committed-position)) | ||
| 9324 | 9358 | ||
| 9325 | (defun markdown--edit-indirect-after-commit-function (beg end) | 9359 | (defun markdown--edit-indirect-after-commit-function (beg end) |
| 9326 | "Corrective logic run on code block content from lines BEG to END. | 9360 | "Corrective logic run on code block content from lines BEG to END. |
| @@ -9342,18 +9376,24 @@ at the END of code blocks." | |||
| 9342 | (interactive) | 9376 | (interactive) |
| 9343 | (save-excursion | 9377 | (save-excursion |
| 9344 | (if (fboundp 'edit-indirect-region) | 9378 | (if (fboundp 'edit-indirect-region) |
| 9345 | (let* ((bounds (markdown-get-enclosing-fenced-block-construct)) | 9379 | (if-let* ((bounds (markdown-get-enclosing-fenced-block-construct)) |
| 9346 | (begin (and bounds (not (null (nth 0 bounds))) (goto-char (nth 0 bounds)) (line-beginning-position 2))) | 9380 | (fence-begin (nth 0 bounds)) |
| 9347 | (end (and bounds(not (null (nth 1 bounds))) (goto-char (nth 1 bounds)) (line-beginning-position 1)))) | 9381 | (fence-end (nth 1 bounds))) |
| 9348 | (if (and begin end) | 9382 | (let* ((original-line (line-number-at-pos)) |
| 9349 | (let* ((indentation (and (goto-char (nth 0 bounds)) (current-indentation))) | 9383 | (original-column (current-column)) |
| 9350 | (lang (markdown-code-block-lang)) | 9384 | (begin (progn (goto-char fence-begin) (line-beginning-position 2))) |
| 9351 | (mode (or (and lang (markdown-get-lang-mode lang)) | 9385 | (line (max 0 (- original-line (line-number-at-pos) 1))) |
| 9352 | markdown-edit-code-block-default-mode)) | 9386 | (indentation (current-indentation)) |
| 9353 | (edit-indirect-guess-mode-function | 9387 | (column (max 0 (- original-column indentation))) |
| 9354 | (lambda (_parent-buffer _beg _end) | 9388 | (end (progn (goto-char fence-end) (line-beginning-position 1))) |
| 9355 | (funcall mode))) | 9389 | (lang (markdown-code-block-lang)) |
| 9356 | (indirect-buf (edit-indirect-region begin end 'display-buffer))) | 9390 | (mode (or (and lang (markdown-get-lang-mode lang)) |
| 9391 | markdown-edit-code-block-default-mode)) | ||
| 9392 | (edit-indirect-guess-mode-function | ||
| 9393 | (lambda (_parent-buffer _beg _end) | ||
| 9394 | (funcall mode))) | ||
| 9395 | (indirect-buf (edit-indirect-region begin end 'display-buffer))) | ||
| 9396 | (with-current-buffer indirect-buf | ||
| 9357 | ;; reset `sh-shell' when indirect buffer | 9397 | ;; reset `sh-shell' when indirect buffer |
| 9358 | (when (and (not (member system-type '(ms-dos windows-nt))) | 9398 | (when (and (not (member system-type '(ms-dos windows-nt))) |
| 9359 | (member mode '(shell-script-mode sh-mode)) | 9399 | (member mode '(shell-script-mode sh-mode)) |
| @@ -9361,16 +9401,17 @@ at the END of code blocks." | |||
| 9361 | (mapcar (lambda (e) (symbol-name (car e))) | 9401 | (mapcar (lambda (e) (symbol-name (car e))) |
| 9362 | sh-ancestor-alist) | 9402 | sh-ancestor-alist) |
| 9363 | '("csh" "rc" "sh")))) | 9403 | '("csh" "rc" "sh")))) |
| 9364 | (with-current-buffer indirect-buf | 9404 | (sh-set-shell lang)) |
| 9365 | (sh-set-shell lang))) | ||
| 9366 | (when (> indentation 0) ;; un-indent in edit-indirect buffer | 9405 | (when (> indentation 0) ;; un-indent in edit-indirect buffer |
| 9367 | (with-current-buffer indirect-buf | 9406 | (indent-rigidly (point-min) (point-max) (- indentation))) |
| 9368 | (indent-rigidly (point-min) (point-max) (- indentation))))) | 9407 | (goto-char (point-min)) |
| 9369 | (user-error "Not inside a GFM or tilde fenced code block"))) | 9408 | (forward-line line) |
| 9409 | (move-to-column column))) | ||
| 9410 | (user-error "Not inside a GFM or tilde fenced code block")) | ||
| 9370 | (when (y-or-n-p "Package edit-indirect needed to edit code blocks. Install it now? ") | 9411 | (when (y-or-n-p "Package edit-indirect needed to edit code blocks. Install it now? ") |
| 9371 | (progn (package-refresh-contents) | 9412 | (package-refresh-contents) |
| 9372 | (package-install 'edit-indirect) | 9413 | (package-install 'edit-indirect) |
| 9373 | (markdown-edit-code-block)))))) | 9414 | (markdown-edit-code-block))))) |
| 9374 | 9415 | ||
| 9375 | 9416 | ||
| 9376 | ;;; Table Editing ============================================================= | 9417 | ;;; Table Editing ============================================================= |
| @@ -10522,7 +10563,7 @@ rows and columns and the column alignment." | |||
| 10522 | (define-key map (kbd "SPC") #'scroll-up-command) | 10563 | (define-key map (kbd "SPC") #'scroll-up-command) |
| 10523 | (define-key map (kbd ">") #'end-of-buffer) | 10564 | (define-key map (kbd ">") #'end-of-buffer) |
| 10524 | (define-key map (kbd "<") #'beginning-of-buffer) | 10565 | (define-key map (kbd "<") #'beginning-of-buffer) |
| 10525 | (define-key map (kbd "q") #'kill-this-buffer) | 10566 | (define-key map (kbd "q") #'kill-current-buffer) |
| 10526 | (define-key map (kbd "?") #'describe-mode) | 10567 | (define-key map (kbd "?") #'describe-mode) |
| 10527 | map) | 10568 | map) |
| 10528 | "Keymap for `markdown-view-mode'.") | 10569 | "Keymap for `markdown-view-mode'.") |
