branch: elpa/markdown-mode
commit 4a05d5bf1fee12bff7ac93828fb087e3eec2ae4d
Author: Shohei YOSHIDA <[email protected]>
Commit: Shohei YOSHIDA <[email protected]>
Implement D&D handler like org-mode
---
markdown-mode.el | 63 ++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 48 insertions(+), 15 deletions(-)
diff --git a/markdown-mode.el b/markdown-mode.el
index 5386c1e7c4..fd82ca6729 100644
--- a/markdown-mode.el
+++ b/markdown-mode.el
@@ -705,6 +705,20 @@ This may also be a cons cell where the behavior for `C-a'
and
(const :tag "on: before closing tags first" t)
(const :tag "reversed: after closing tags first"
reversed))))
:package-version '(markdown-mode . "2.7"))
+
+(defcustom markdown-yank-dnd-method 'file-link
+ "Action to perform on the dropped files.
+When the value is the symbol,
+ - `copy-and-insert' -- copy file in current directory and insert its link
+ - `open' -- open dropped file in Emacs
+ - `insert-link' -- insert link of dropped/pasted file
+ - `ask' -- ask what to do out of the above."
+ :group 'markdown
+ :package-version '(markdown-mode "2.8")
+ :type '(choice (const :tag "Copy and insert" copy-and-insert)
+ (const :tag "Open file" open)
+ (const :tag "Insert file link" file-link)
+ (const :tag "Ask what to do" ask)))
;;; Markdown-Specific `rx' Macro ==============================================
@@ -9898,12 +9912,8 @@ indicate that sorting should be done in reverse order."
(t 1))))
(sorting-type
(or sorting-type
- (progn
- ;; workaround #641
- ;; Emacs < 28 hides prompt message by another message. This
erases it.
- (message "")
- (read-char-exclusive
- "Sort type: [a]lpha [n]umeric (A/N means reversed): ")))))
+ (read-char-exclusive
+ "Sort type: [a]lpha [n]umeric (A/N means reversed): "))))
(save-restriction
;; Narrow buffer to appropriate sorting area
(if (region-active-p)
@@ -10119,18 +10129,41 @@ rows and columns and the column alignment."
(insert " "))
(setq files (cdr files))))))
-(defun markdown--dnd-local-file-handler (url _action)
+(defun markdown--dnd-read-method ()
+ (let ((choice (read-multiple-choice "What to do with file?"
+ '((?c "copy and insert")
+ (?o "open")
+ (?i "insert link")))))
+ (cl-case (car choice)
+ (?c 'copy-and-insert)
+ (?o 'open)
+ (?i 'insert)
+ (otherwise (markdown--dnd-read-method)))))
+
+(defun markdown--dnd-insert-path (filename)
+ (let ((mimetype (mailcap-file-name-to-mime-type filename))
+ (link-text "link text"))
+ (when (string-match-p "\\s-" filename)
+ (setq filename (concat "<" filename ">")))
+ (if (string-prefix-p "image/" mimetype)
+ (markdown-insert-inline-image link-text filename)
+ (markdown-insert-inline-link link-text filename))))
+
+(defun markdown--dnd-local-file-handler (url action)
(require 'mailcap)
(require 'dnd)
(let* ((filename (dnd-get-local-file-name url))
- (mimetype (mailcap-file-name-to-mime-type filename))
- (file (file-relative-name filename))
- (link-text "link text"))
- (when (string-match-p "\\s-" file)
- (setq file (concat "<" file ">")))
- (if (string-prefix-p "image/" mimetype)
- (markdown-insert-inline-image link-text file)
- (markdown-insert-inline-link link-text file))))
+ (method (if (eq markdown-yank-dnd-method 'ask)
+ (markdown--dnd-read-method)
+ markdown-yank-dnd-method)))
+ (cl-case method
+ (copy-and-insert
+ (let ((copied (expand-file-name (file-name-nondirectory filename))))
+ (copy-file filename copied)
+ (markdown--dnd-insert-path (file-relative-name copied))))
+ (open
+ (dnd-open-local-file url action))
+ (insert (markdown--dnd-insert-path (file-relative-name filename))))))
(defun markdown--dnd-multi-local-file-handler (urls action)
(let ((multile-urls-p (> (length urls) 1)))