|
53 | 53 | (declare-function sh-set-shell "sh-script")
|
54 | 54 | (declare-function mailcap-file-name-to-mime-type "mailcap")
|
55 | 55 | (declare-function dnd-get-local-file-name "dnd")
|
| 56 | +(declare-function dnd-open-local-file "dnd") |
56 | 57 |
|
57 | 58 | ;; for older emacs<29
|
58 | 59 | (declare-function mailcap-mime-type-to-extension "mailcap")
|
@@ -705,6 +706,20 @@ This may also be a cons cell where the behavior for `C-a' and
|
705 | 706 | (const :tag "on: before closing tags first" t)
|
706 | 707 | (const :tag "reversed: after closing tags first" reversed))))
|
707 | 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 | 724 | ;;; Markdown-Specific `rx' Macro ==============================================
|
710 | 725 |
|
@@ -9898,12 +9913,8 @@ indicate that sorting should be done in reverse order."
|
9898 | 9913 | (t 1))))
|
9899 | 9914 | (sorting-type
|
9900 | 9915 | (or sorting-type
|
9901 |
| - (progn |
9902 |
| - ;; workaround #641 |
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): "))))) |
| 9916 | + (read-char-exclusive |
| 9917 | + "Sort type: [a]lpha [n]umeric (A/N means reversed): ")))) |
9907 | 9918 | (save-restriction
|
9908 | 9919 | ;; Narrow buffer to appropriate sorting area
|
9909 | 9920 | (if (region-active-p)
|
@@ -10119,18 +10130,41 @@ rows and columns and the column alignment."
|
10119 | 10130 | (insert " "))
|
10120 | 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 | 10154 | (require 'mailcap)
|
10124 | 10155 | (require 'dnd)
|
10125 | 10156 | (let* ((filename (dnd-get-local-file-name url))
|
10126 |
| - (mimetype (mailcap-file-name-to-mime-type filename)) |
10127 |
| - (file (file-relative-name filename)) |
10128 |
| - (link-text "link text")) |
10129 |
| - (when (string-match-p "\\s-" file) |
10130 |
| - (setq file (concat "<" file ">"))) |
10131 |
| - (if (string-prefix-p "image/" mimetype) |
10132 |
| - (markdown-insert-inline-image link-text file) |
10133 |
| - (markdown-insert-inline-link link-text file)))) |
| 10157 | + (method (if (eq markdown-yank-dnd-method 'ask) |
| 10158 | + (markdown--dnd-read-method) |
| 10159 | + markdown-yank-dnd-method))) |
| 10160 | + (cl-case method |
| 10161 | + (copy-and-insert |
| 10162 | + (let ((copied (expand-file-name (file-name-nondirectory filename)))) |
| 10163 | + (copy-file filename copied) |
| 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 | 10169 | (defun markdown--dnd-multi-local-file-handler (urls action)
|
10136 | 10170 | (let ((multile-urls-p (> (length urls) 1)))
|
|
0 commit comments