diff options
| author | Simeon Simeonov | 2025-03-14 05:43:36 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2025-03-14 05:43:36 +0100 |
| commit | a429db57b6fc60d6bd026bd530cdb80554101622 (patch) | |
| tree | 562f595e2db8d8a5af2ee711be99f19087754583 | |
| parent | bcd993046ffaa3390bcf3252db8ba69d4610191c (diff) | |
Upgrade markdown-mode
| -rw-r--r-- | .emacs.d/lisp/markdown-mode.el | 78 |
1 files changed, 56 insertions, 22 deletions
diff --git a/.emacs.d/lisp/markdown-mode.el b/.emacs.d/lisp/markdown-mode.el index a914eb3..311050f 100644 --- a/.emacs.d/lisp/markdown-mode.el +++ b/.emacs.d/lisp/markdown-mode.el | |||
| @@ -53,6 +53,7 @@ | |||
| 53 | (declare-function sh-set-shell "sh-script") | 53 | (declare-function sh-set-shell "sh-script") |
| 54 | (declare-function mailcap-file-name-to-mime-type "mailcap") | 54 | (declare-function mailcap-file-name-to-mime-type "mailcap") |
| 55 | (declare-function dnd-get-local-file-name "dnd") | 55 | (declare-function dnd-get-local-file-name "dnd") |
| 56 | (declare-function dnd-open-local-file "dnd") | ||
| 56 | 57 | ||
| 57 | ;; for older emacs<29 | 58 | ;; for older emacs<29 |
| 58 | (declare-function mailcap-mime-type-to-extension "mailcap") | 59 | (declare-function mailcap-mime-type-to-extension "mailcap") |
| @@ -108,7 +109,7 @@ Any changes to the output buffer made by this hook will be saved.") | |||
| 108 | :group 'text | 109 | :group 'text |
| 109 | :link '(url-link "https://jblevins.org/projects/markdown-mode/")) | 110 | :link '(url-link "https://jblevins.org/projects/markdown-mode/")) |
| 110 | 111 | ||
| 111 | (defcustom markdown-command (let ((command (cl-loop for cmd in '("markdown" "pandoc" "markdown_py") | 112 | (defcustom markdown-command (let ((command (cl-loop for cmd in '("markdown" "pandoc" "markdown_py" "cmark" "cmark-gfm") |
| 112 | when (executable-find cmd) | 113 | when (executable-find cmd) |
| 113 | return (file-name-nondirectory it)))) | 114 | return (file-name-nondirectory it)))) |
| 114 | (or command "markdown")) | 115 | (or command "markdown")) |
| @@ -705,6 +706,20 @@ This may also be a cons cell where the behavior for `C-a' and | |||
| 705 | (const :tag "on: before closing tags first" t) | 706 | (const :tag "on: before closing tags first" t) |
| 706 | (const :tag "reversed: after closing tags first" reversed)))) | 707 | (const :tag "reversed: after closing tags first" reversed)))) |
| 707 | :package-version '(markdown-mode . "2.7")) | 708 | :package-version '(markdown-mode . "2.7")) |
| 709 | |||
| 710 | (defcustom markdown-yank-dnd-method 'file-link | ||
| 711 | "Action to perform on the dropped files. | ||
| 712 | When the value is the symbol, | ||
| 713 | - `copy-and-insert' -- copy file in current directory and insert its link | ||
| 714 | - `open' -- open dropped file in Emacs | ||
| 715 | - `insert-link' -- insert link of dropped/pasted file | ||
| 716 | - `ask' -- ask what to do out of the above." | ||
| 717 | :group 'markdown | ||
| 718 | :package-version '(markdown-mode "2.8") | ||
| 719 | :type '(choice (const :tag "Copy and insert" copy-and-insert) | ||
| 720 | (const :tag "Open file" open) | ||
| 721 | (const :tag "Insert file link" file-link) | ||
| 722 | (const :tag "Ask what to do" ask))) | ||
| 708 | 723 | ||
| 709 | ;;; Markdown-Specific `rx' Macro ============================================== | 724 | ;;; Markdown-Specific `rx' Macro ============================================== |
| 710 | 725 | ||
| @@ -7694,8 +7709,8 @@ Return the name of the output buffer used." | |||
| 7694 | (erase-buffer)) | 7709 | (erase-buffer)) |
| 7695 | (if (stringp command) | 7710 | (if (stringp command) |
| 7696 | (if (not (null command-args)) | 7711 | (if (not (null command-args)) |
| 7697 | (apply #'call-process-region begin-region end-region command nil buf nil command-args) | 7712 | (apply #'call-process-region begin-region end-region command nil (list buf nil) nil command-args) |
| 7698 | (call-process-region begin-region end-region command nil buf)) | 7713 | (call-process-region begin-region end-region command nil (list buf nil))) |
| 7699 | (if markdown-command-needs-filename | 7714 | (if markdown-command-needs-filename |
| 7700 | (if (not buffer-file-name) | 7715 | (if (not buffer-file-name) |
| 7701 | (user-error "Must be visiting a file") | 7716 | (user-error "Must be visiting a file") |
| @@ -9898,12 +9913,8 @@ indicate that sorting should be done in reverse order." | |||
| 9898 | (t 1)))) | 9913 | (t 1)))) |
| 9899 | (sorting-type | 9914 | (sorting-type |
| 9900 | (or sorting-type | 9915 | (or sorting-type |
| 9901 | (progn | 9916 | (read-char-exclusive |
| 9902 | ;; workaround #641 | 9917 | "Sort type: [a]lpha [n]umeric (A/N means reversed): ")))) |
| 9903 | ;; Emacs < 28 hides prompt message by another message. This erases it. | ||
| 9904 | (message "") | ||
| 9905 | (read-char-exclusive | ||
| 9906 | "Sort type: [a]lpha [n]umeric (A/N means reversed): "))))) | ||
| 9907 | (save-restriction | 9918 | (save-restriction |
| 9908 | ;; Narrow buffer to appropriate sorting area | 9919 | ;; Narrow buffer to appropriate sorting area |
| 9909 | (if (region-active-p) | 9920 | (if (region-active-p) |
| @@ -10119,18 +10130,41 @@ rows and columns and the column alignment." | |||
| 10119 | (insert " ")) | 10130 | (insert " ")) |
| 10120 | (setq files (cdr files)))))) | 10131 | (setq files (cdr files)))))) |
| 10121 | 10132 | ||
| 10122 | (defun markdown--dnd-local-file-handler (url _action) | 10133 | (defun markdown--dnd-read-method () |
| 10134 | (let ((choice (read-multiple-choice "What to do with file?" | ||
| 10135 | '((?c "copy and insert") | ||
| 10136 | (?o "open") | ||
| 10137 | (?i "insert link"))))) | ||
| 10138 | (cl-case (car choice) | ||
| 10139 | (?c 'copy-and-insert) | ||
| 10140 | (?o 'open) | ||
| 10141 | (?i 'insert) | ||
| 10142 | (otherwise (markdown--dnd-read-method))))) | ||
| 10143 | |||
| 10144 | (defun markdown--dnd-insert-path (filename) | ||
| 10145 | (let ((mimetype (mailcap-file-name-to-mime-type filename)) | ||
| 10146 | (link-text "link text")) | ||
| 10147 | (when (string-match-p "\\s-" filename) | ||
| 10148 | (setq filename (concat "<" filename ">"))) | ||
| 10149 | (if (string-prefix-p "image/" mimetype) | ||
| 10150 | (markdown-insert-inline-image link-text filename) | ||
| 10151 | (markdown-insert-inline-link link-text filename)))) | ||
| 10152 | |||
| 10153 | (defun markdown--dnd-local-file-handler (url action) | ||
| 10123 | (require 'mailcap) | 10154 | (require 'mailcap) |
| 10124 | (require 'dnd) | 10155 | (require 'dnd) |
| 10125 | (let* ((filename (dnd-get-local-file-name url)) | 10156 | (let* ((filename (dnd-get-local-file-name url)) |
| 10126 | (mimetype (mailcap-file-name-to-mime-type filename)) | 10157 | (method (if (eq markdown-yank-dnd-method 'ask) |
| 10127 | (file (file-relative-name filename)) | 10158 | (markdown--dnd-read-method) |
| 10128 | (link-text "link text")) | 10159 | markdown-yank-dnd-method))) |
| 10129 | (when (string-match-p "\\s-" file) | 10160 | (cl-case method |
| 10130 | (setq file (concat "<" file ">"))) | 10161 | (copy-and-insert |
| 10131 | (if (string-prefix-p "image/" mimetype) | 10162 | (let ((copied (expand-file-name (file-name-nondirectory filename)))) |
| 10132 | (markdown-insert-inline-image link-text file) | 10163 | (copy-file filename copied) |
| 10133 | (markdown-insert-inline-link link-text file)))) | 10164 | (markdown--dnd-insert-path (file-relative-name copied)))) |
| 10165 | (open | ||
| 10166 | (dnd-open-local-file url action)) | ||
| 10167 | (insert (markdown--dnd-insert-path (file-relative-name filename)))))) | ||
| 10134 | 10168 | ||
| 10135 | (defun markdown--dnd-multi-local-file-handler (urls action) | 10169 | (defun markdown--dnd-multi-local-file-handler (urls action) |
| 10136 | (let ((multile-urls-p (> (length urls) 1))) | 10170 | (let ((multile-urls-p (> (length urls) 1))) |
| @@ -10197,10 +10231,10 @@ rows and columns and the column alignment." | |||
| 10197 | ;; Add a buffer-local hook to reload after file-local variables are read | 10231 | ;; Add a buffer-local hook to reload after file-local variables are read |
| 10198 | (add-hook 'hack-local-variables-hook #'markdown-handle-local-variables nil t) | 10232 | (add-hook 'hack-local-variables-hook #'markdown-handle-local-variables nil t) |
| 10199 | ;; For imenu support | 10233 | ;; For imenu support |
| 10200 | (setq imenu-create-index-function | 10234 | (setq-local imenu-create-index-function (if markdown-nested-imenu-heading-index |
| 10201 | (if markdown-nested-imenu-heading-index | 10235 | #'markdown-imenu-create-nested-index |
| 10202 | #'markdown-imenu-create-nested-index | 10236 | #'markdown-imenu-create-flat-index) |
| 10203 | #'markdown-imenu-create-flat-index)) | 10237 | imenu-submenus-on-top nil) |
| 10204 | 10238 | ||
| 10205 | ;; Defun movement | 10239 | ;; Defun movement |
| 10206 | (setq-local beginning-of-defun-function #'markdown-beginning-of-defun) | 10240 | (setq-local beginning-of-defun-function #'markdown-beginning-of-defun) |
