From a17a4f747cd6b0e6628b253c17637810fc604faa Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Wed, 21 May 2025 14:52:14 +0200 Subject: [PATCH] update markdown-mode --- .../markdown-mode-autoloads.el | 0 .../markdown-mode-pkg.el | 10 +- .../markdown-mode.el | 454 +++++++++++++----- 3 files changed, 327 insertions(+), 137 deletions(-) rename elpa/{markdown-mode-20241117.1510 => markdown-mode-20250501.551}/markdown-mode-autoloads.el (100%) rename elpa/{markdown-mode-20241117.1510 => markdown-mode-20250501.551}/markdown-mode-pkg.el (58%) rename elpa/{markdown-mode-20241117.1510 => markdown-mode-20250501.551}/markdown-mode.el (96%) diff --git a/elpa/markdown-mode-20241117.1510/markdown-mode-autoloads.el b/elpa/markdown-mode-20250501.551/markdown-mode-autoloads.el similarity index 100% rename from elpa/markdown-mode-20241117.1510/markdown-mode-autoloads.el rename to elpa/markdown-mode-20250501.551/markdown-mode-autoloads.el diff --git a/elpa/markdown-mode-20241117.1510/markdown-mode-pkg.el b/elpa/markdown-mode-20250501.551/markdown-mode-pkg.el similarity index 58% rename from elpa/markdown-mode-20241117.1510/markdown-mode-pkg.el rename to elpa/markdown-mode-20250501.551/markdown-mode-pkg.el index c91c3c46..4b9ed90b 100644 --- a/elpa/markdown-mode-20241117.1510/markdown-mode-pkg.el +++ b/elpa/markdown-mode-20250501.551/markdown-mode-pkg.el @@ -1,10 +1,10 @@ ;; -*- no-byte-compile: t; lexical-binding: nil -*- -(define-package "markdown-mode" "20241117.1510" +(define-package "markdown-mode" "20250501.551" "Major mode for Markdown-formatted text." - '((emacs "27.1")) - :url "https://github.com/jrblevin/markdown-mode" - :commit "b8637bae075231d70fe7f845305eaba2c0240d89" - :revdesc "b8637bae0752" + '((emacs "28.1")) + :url "https://jblevins.org/projects/markdown-mode/" + :commit "90ad4af79a8bb65a3a5cdd6314be44abd9517cfc" + :revdesc "90ad4af79a8b" :keywords '("markdown" "github flavored markdown" "itex") :authors '(("Jason R. Blevins" . "jblevins@xbeta.org")) :maintainers '(("Jason R. Blevins" . "jblevins@xbeta.org"))) diff --git a/elpa/markdown-mode-20241117.1510/markdown-mode.el b/elpa/markdown-mode-20250501.551/markdown-mode.el similarity index 96% rename from elpa/markdown-mode-20241117.1510/markdown-mode.el rename to elpa/markdown-mode-20250501.551/markdown-mode.el index 8cfa90b1..d1e5d3a1 100644 --- a/elpa/markdown-mode-20241117.1510/markdown-mode.el +++ b/elpa/markdown-mode-20250501.551/markdown-mode.el @@ -6,9 +6,9 @@ ;; Author: Jason R. Blevins ;; Maintainer: Jason R. Blevins ;; Created: May 24, 2007 -;; Package-Version: 20241117.1510 -;; Package-Revision: b8637bae0752 -;; Package-Requires: ((emacs "27.1")) +;; Package-Version: 20250501.551 +;; Package-Revision: 90ad4af79a8b +;; Package-Requires: ((emacs "28.1")) ;; Keywords: Markdown, GitHub Flavored Markdown, itex ;; URL: https://jblevins.org/projects/markdown-mode/ @@ -54,6 +54,7 @@ (declare-function sh-set-shell "sh-script") (declare-function mailcap-file-name-to-mime-type "mailcap") (declare-function dnd-get-local-file-name "dnd") +(declare-function dnd-open-local-file "dnd") ;; for older emacs<29 (declare-function mailcap-mime-type-to-extension "mailcap") @@ -63,7 +64,7 @@ ;;; Constants ================================================================= -(defconst markdown-mode-version "2.7-alpha" +(defconst markdown-mode-version "2.8-alpha" "Markdown mode version number.") (defconst markdown-output-buffer-name "*markdown-output*" @@ -109,7 +110,7 @@ Any changes to the output buffer made by this hook will be saved.") :group 'text :link '(url-link "https://jblevins.org/projects/markdown-mode/")) -(defcustom markdown-command (let ((command (cl-loop for cmd in '("markdown" "pandoc" "markdown_py") +(defcustom markdown-command (let ((command (cl-loop for cmd in '("markdown" "pandoc" "markdown_py" "cmark" "cmark-gfm") when (executable-find cmd) return (file-name-nondirectory it)))) (or command "markdown")) @@ -263,11 +264,11 @@ This is the default search behavior of Ikiwiki." :package-version '(markdown-mode . "2.2")) (defcustom markdown-wiki-link-search-type nil - "Searching type for markdown wiki link. + "A list of options for searching for markdown wiki links. -sub-directories: search for wiki link targets in sub directories -parent-directories: search for wiki link targets in parent directories -project: search for wiki link targets under project root" +`sub-directories': search for wiki link targets in sub directories +`parent-directories': search for wiki link targets in parent directories +`project': search for wiki link targets under project root" :group 'markdown :type '(set (const :tag "search wiki link from subdirectories" sub-directories) @@ -278,6 +279,16 @@ project: search for wiki link targets under project root" (make-obsolete-variable 'markdown-wiki-link-search-subdirectories 'markdown-wiki-link-search-type "2.5") (make-obsolete-variable 'markdown-wiki-link-search-parent-directories 'markdown-wiki-link-search-type "2.5") +(make-obsolete 'markdown-match-wiki-link nil "2.8") +(make-obsolete 'markdown-highlight-wiki-link nil "2.8") +(make-obsolete 'markdown-unfontify-region-wiki-links nil "2.8") +(make-obsolete 'markdown-fontify-region-wiki-links nil "2.8") +(make-obsolete 'markdown-extend-changed-region nil "2.8") +(make-obsolete 'markdown-check-change-for-wiki-link nil "2.8") +(make-obsolete 'markdown-check-change-for-wiki-link-after-change nil "2.8") +(make-obsolete 'markdown-fontify-buffer-wiki-links nil "2.8") +(make-obsolete 'markdown-setup-wiki-link-hooks nil "2.8") + (defcustom markdown-wiki-link-fontify-missing nil "When non-nil, change wiki link face according to existence of target files. This is expensive because it requires checking for the file each time the buffer @@ -288,6 +299,13 @@ cause lag when typing on slower machines." :safe 'booleanp :package-version '(markdown-mode . "2.2")) +(defcustom markdown-wiki-link-retain-case nil + "When non-nil, wiki link file names do not have their case changed." + :group 'markdown + :type 'boolean + :safe 'booleanp + :package-version '(markdown-mode . "2.7")) + (defcustom markdown-uri-types '("acap" "cid" "data" "dav" "fax" "file" "ftp" "geo" "gopher" "http" "https" "imap" "ldap" "mailto" @@ -699,6 +717,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 ============================================== @@ -909,7 +941,6 @@ This matches typical bracketed [[WikiLinks]] as well as \\='aliased wiki links of the form [[PageName|link text]]. The meanings of the first and second components depend on the value of `markdown-wiki-link-alias-first'. - Group 1 matches the entire link. Group 2 matches the opening square brackets. Group 3 matches the first component of the wiki link. @@ -1171,6 +1202,10 @@ escape character (see `markdown-match-escape').") If POS is not given, use point instead." (get-text-property (or pos (point)) 'markdown-comment)) +(defsubst markdown-in-inline-code-p (pos) + "Return non-nil if POS is in inline code." + (equal (get-text-property pos 'face) '(markdown-inline-code-face))) + (defun markdown--face-p (pos faces) "Return non-nil if face of POS contain FACES." (let ((face-prop (get-text-property pos 'face))) @@ -1982,12 +2017,14 @@ inline code fragments and code blocks." (defface markdown-link-face '((t (:inherit link))) - "Face for links." + "Face for link text, ie the alias portion of a link. +If a wiki link does not have an alias portion, use this face +for the entire link." :group 'markdown-faces) (defface markdown-missing-link-face '((t (:inherit font-lock-warning-face))) - "Face for missing links." + "Face for the link text if the link points to a missing file." :group 'markdown-faces) (defface markdown-reference-face @@ -2258,6 +2295,7 @@ Depending on your font, some reasonable choices are: (7 markdown-markup-properties))) (markdown-fontify-inline-links) (markdown-fontify-reference-links) + (markdown-fontify-wiki-links) (,markdown-regex-reference-definition . ((1 'markdown-markup-face) ; [ (2 'markdown-reference-face) ; label (3 'markdown-markup-face) ; ] @@ -2294,8 +2332,7 @@ Depending on your font, some reasonable choices are: (markdown-fontify-sub-superscripts) (markdown-match-inline-attributes . ((0 markdown-markup-properties prepend))) (markdown-match-leanpub-sections . ((0 markdown-markup-properties))) - (markdown-fontify-blockquotes) - (markdown-match-wiki-link . ((0 'markdown-link-face prepend)))) + (markdown-fontify-blockquotes)) "Syntax highlighting for Markdown files.") ;; Footnotes @@ -3397,7 +3434,8 @@ the buffer)." (markdown-code-block-at-pos begin)) (progn (goto-char (min (1+ begin) last)) (when (< (point) last) - (markdown-match-wiki-link last))) + (with-no-warnings + (markdown-match-wiki-link last)))) (set-match-data (list begin end)) t)))) @@ -3684,6 +3722,18 @@ SEQ may be an atom or a sequence." (defvar markdown-mode-syntax-table (let ((tab (make-syntax-table text-mode-syntax-table))) (modify-syntax-entry ?\" "." tab) + (modify-syntax-entry ?$ "." tab) ; Might appear in inline content + (modify-syntax-entry ?% "." tab) ; Could appear in URLs + (modify-syntax-entry ?* "." tab) ; Emphasis (bold/italic) + (modify-syntax-entry ?+ "." tab) ; Used in lists + (modify-syntax-entry ?/ "." tab) ; Might appear in inline content or URLs + (modify-syntax-entry ?< "." tab) ; For autolinks and embedded HTML + (modify-syntax-entry ?= "." tab) ; Underlining in setext headers + (modify-syntax-entry ?> "." tab) ; Blockquotes and HTML + (modify-syntax-entry ?_ "." tab) ; Used for emphasis/bold + (modify-syntax-entry ?| "." tab) ; Used in tables + (modify-syntax-entry ?& "." tab) ; HTML entities + (modify-syntax-entry ?' "." tab) ; Apostrophe as punctuation tab) "Syntax table for `markdown-mode'.") @@ -5182,6 +5232,7 @@ list simply adds a blank line)." (markdown-indent-on-enter (let (bounds) (if (and (memq markdown-indent-on-enter '(indent-and-new-item)) + (not (markdown-code-block-at-point-p)) (setq bounds (markdown-cur-list-item-bounds))) (let ((beg (cl-first bounds)) (end (cl-second bounds)) @@ -5228,8 +5279,7 @@ Otherwise, do normal delete by repeating (back-to-indentation) (unless (looking-at-p "[ \t]*$") (setq mincol (min mincol (current-column)))) - (forward-line 1) - )) + (forward-line 1))) mincol)) (defun markdown-indent-region (beg end arg) @@ -5704,7 +5754,39 @@ Assumes match data is available for `markdown-regex-italic'." "Keymap for `gfm-mode'. See also `markdown-mode-map'.") - + +;;; Text Properties =========================================================== + +(defconst markdown--markup-props (list 'invisible 'markdown-markup + 'rear-nonsticky t + 'font-lock-multiline t)) + +(defconst markdown--title-props (list 'invisible 'markdown-markup + 'font-lock-multiline t)) + +(defun markdown--url-props () + (if markdown-mouse-follow-link + (list 'invisible 'markdown-markup + 'keymap markdown-mode-mouse-map + 'mouse-face 'markdown-highlight-face + 'font-lock-multiline t) + (list 'invisible 'markdown-markup + 'keymap markdown-mode-mouse-map + 'font-lock-multiline t))) + +(defun markdown--link-props (url &optional title) + "Return a property list for URL with optional TITLE." + (let ((echo-text (if title (concat title "\n" url) url))) + (if markdown-mouse-follow-link + (list 'keymap markdown-mode-mouse-map + 'mouse-face 'markdown-highlight-face + 'font-lock-multiline t + 'help-echo echo-text) + (list 'keymap markdown-mode-mouse-map + 'font-lock-multiline t + 'help-echo echo-text)))) + + ;;; Menu ====================================================================== (easy-menu-define markdown-mode-menu markdown-mode-map @@ -7683,8 +7765,8 @@ Return the name of the output buffer used." (erase-buffer)) (if (stringp command) (if (not (null command-args)) - (apply #'call-process-region begin-region end-region command nil buf nil command-args) - (call-process-region begin-region end-region command nil buf)) + (apply #'call-process-region begin-region end-region command nil (list buf nil) nil command-args) + (call-process-region begin-region end-region command nil (list buf nil))) (if markdown-command-needs-filename (if (not buffer-file-name) (user-error "Must be visiting a file") @@ -7737,7 +7819,9 @@ Standalone XHTML output is identified by an occurrence of (defun markdown-stylesheet-link-string (stylesheet-path) (concat "")) (defun markdown-escape-title (title) @@ -8180,38 +8264,20 @@ Translate filenames using `markdown-filename-translate-function'." (title-start (match-beginning 7)) (title-end (match-end 7)) (title (match-string-no-properties 7)) - ;; Markup part - (mp (list 'invisible 'markdown-markup - 'rear-nonsticky t - 'font-lock-multiline t)) - ;; Link part (without face) - (lp (list 'keymap markdown-mode-mouse-map - 'mouse-face 'markdown-highlight-face - 'font-lock-multiline t - 'help-echo (if title (concat title "\n" url) url))) - ;; URL part - (up (list 'keymap markdown-mode-mouse-map - 'invisible 'markdown-markup - 'mouse-face 'markdown-highlight-face - 'font-lock-multiline t)) - ;; URL composition character - (url-char (markdown--first-displayable markdown-url-compose-char)) - ;; Title part - (tp (list 'invisible 'markdown-markup - 'font-lock-multiline t))) + (url-char (markdown--first-displayable markdown-url-compose-char))) (dolist (g '(1 2 4 5 8)) (when (match-end g) - (add-text-properties (match-beginning g) (match-end g) mp) + (add-text-properties (match-beginning g) (match-end g) markdown--markup-props) (add-face-text-property (match-beginning g) (match-end g) 'markdown-markup-face))) ;; Preserve existing faces applied to link part (e.g., inline code) (when link-start - (add-text-properties link-start link-end lp) + (add-text-properties link-start link-end (markdown--link-props url title)) (add-face-text-property link-start link-end 'markdown-link-face)) (when url-start - (add-text-properties url-start url-end up) + (add-text-properties url-start url-end (markdown--url-props)) (add-face-text-property url-start url-end 'markdown-url-face)) (when title-start - (add-text-properties url-end title-end tp) + (add-text-properties url-end title-end markdown--title-props) (add-face-text-property url-end title-end 'markdown-link-title-face)) (when (and markdown-hide-urls url-start) (compose-region url-start (or title-end url-end) url-char)) @@ -8224,13 +8290,8 @@ Translate filenames using `markdown-filename-translate-function'." (link-end (match-end 3)) (ref-start (match-beginning 6)) (ref-end (match-end 6)) - ;; Markup part - (mp (list 'invisible 'markdown-markup - 'rear-nonsticky t - 'font-lock-multiline t)) - ;; Link part + ;; Link properties (lp (list 'keymap markdown-mode-mouse-map - 'mouse-face 'markdown-highlight-face 'font-lock-multiline t 'help-echo (lambda (_ __ pos) (save-match-data @@ -8240,12 +8301,14 @@ Translate filenames using `markdown-filename-translate-function'." "Undefined reference")))))) ;; URL composition character (url-char (markdown--first-displayable markdown-url-compose-char)) - ;; Reference part + ;; Reference properties (rp (list 'invisible 'markdown-markup 'font-lock-multiline t))) + (when markdown-mouse-follow-link + (setq lp (append lp '(mouse-face markdown-highlight-face)))) (dolist (g '(1 2 4 5 8)) (when (match-end g) - (add-text-properties (match-beginning g) (match-end g) mp) + (add-text-properties (match-beginning g) (match-end g) markdown--markup-props) (add-face-text-property (match-beginning g) (match-end g) 'markdown-markup-face))) (when link-start (add-text-properties link-start link-end lp) @@ -8257,25 +8320,93 @@ Translate filenames using `markdown-filename-translate-function'." (compose-region ref-start ref-end url-char))) t))) +(defun markdown-fontify-wiki-links (last) + "Add text properties to next wiki link from point to LAST." + (when (and markdown-enable-wiki-links + (markdown-match-inline-generic markdown-regex-wiki-link last)) + (let* ((begin (match-beginning 1)) + (end (match-end 1)) + (beg2 (match-beginning 2)) + (end2 (match-end 2)) + (beg3 (match-beginning 3)) + (end3 (match-end 3)) + (beg4 (match-beginning 4)) + (end4 (match-end 4)) + (beg5 (match-beginning 5)) + (end5 (match-end 5)) + (beg6 (match-beginning 6)) + (end6 (match-end 6)) + (part1 (match-string-no-properties 3)) + (part2 (match-string-no-properties 5)) + (aliasp (string-equal (match-string-no-properties 4) "|")) + (file-name (markdown-convert-wiki-link-to-filename (markdown-wiki-link-link))) + (file-missing-p (not (file-exists-p file-name)))) + (if (or (markdown-in-comment-p begin) + (markdown-in-comment-p end) + (markdown-inline-code-at-pos-p begin) + (markdown-inline-code-at-pos-p end) + (markdown-code-block-at-pos begin)) + (progn (goto-char (min (1+ begin) last)) + (when (< (point) last) + (markdown-fontify-wiki-links last))) + ;; Add text properties for hiding markup + (progn + ;; Propertize opening and closing brackets + (add-text-properties beg2 end2 markdown--markup-props) + (add-face-text-property beg2 end2 'markdown-markup-face) + (add-text-properties beg6 end6 markdown--markup-props) + (add-face-text-property beg6 end6 'markdown-markup-face) + (if aliasp + (progn + ;; Propertize pipe separating URL from link text + (add-text-properties beg4 end4 markdown--markup-props) + (add-face-text-property beg4 end4 'markdown-markup-face) + (if markdown-wiki-link-alias-first + (progn + ;; Properties alias portion of link + (add-text-properties beg3 end3 (markdown--link-props part2)) + (add-face-text-property beg3 end3 'markdown-link-face) + (add-text-properties beg5 end5 (markdown--url-props)) + (add-text-properties beg5 end5 '(invisible markdown-markup)) + (add-face-text-property beg5 end5 'markdown-url-face) + (when (and file-missing-p markdown-wiki-link-fontify-missing) + (put-text-property beg3 end3 'face 'markdown-missing-link-face))) + (progn + ;; Properties URL portion of link + (add-text-properties beg3 end3 (markdown--url-props)) + (add-text-properties beg3 end3 '(invisible markdown-markup)) + (add-face-text-property beg3 end3 'markdown-url-face) + (add-text-properties beg5 end5 (markdown--link-props part1)) + (add-face-text-property beg5 end5 'markdown-link-face) + (when (and file-missing-p markdown-wiki-link-fontify-missing) + (put-text-property beg5 end5 'face 'markdown-missing-link-face))))) + (progn + ;; Properties link as link text + (add-text-properties beg3 end3 (markdown--link-props part1)) + (add-face-text-property beg3 end3 'markdown-link-face) + (when (and file-missing-p markdown-wiki-link-fontify-missing) + (put-text-property beg3 end3 'face 'markdown-missing-link-face))))) + (set-match-data (list begin end)) + t)))) + (defun markdown-fontify-angle-uris (last) "Add text properties to angle URIs from point to LAST." (when (markdown-match-angle-uris last) - (let* ((url-start (match-beginning 2)) - (url-end (match-end 2)) - ;; Markup part - (mp (list 'face 'markdown-markup-face - 'invisible 'markdown-markup - 'rear-nonsticky t - 'font-lock-multiline t)) - ;; URI part - (up (list 'keymap markdown-mode-mouse-map - 'face 'markdown-plain-url-face - 'mouse-face 'markdown-highlight-face - 'font-lock-multiline t))) - (dolist (g '(1 3)) - (add-text-properties (match-beginning g) (match-end g) mp)) - (add-text-properties url-start url-end up) - t))) + (let ((url-start (match-beginning 2)) + (url-end (match-end 2))) + (unless (or (markdown-in-inline-code-p url-start) + (markdown-in-inline-code-p url-end)) + (let ((mp (append '(face markdown-markup-face) (cl-copy-list markdown--markup-props))) + ;; URI part + (up (list 'keymap markdown-mode-mouse-map + 'face 'markdown-plain-url-face + 'font-lock-multiline t))) + (when markdown-mouse-follow-link + (setq up (append up '(mouse-face markdown-highlight-face)))) + (dolist (g '(1 3)) + (add-text-properties (match-beginning g) (match-end g) mp)) + (add-text-properties url-start url-end up) + t))))) (defun markdown-fontify-plain-uris (last) "Add text properties to plain URLs from point to LAST." @@ -8284,9 +8415,10 @@ Translate filenames using `markdown-filename-translate-function'." (end (match-end 0)) (props (list 'keymap markdown-mode-mouse-map 'face 'markdown-plain-url-face - 'mouse-face 'markdown-highlight-face 'rear-nonsticky t 'font-lock-multiline t))) + (when markdown-mouse-follow-link + (setq props (append props '(mouse-face markdown-highlight-face)))) (add-text-properties start end props) t))) @@ -8338,6 +8470,11 @@ The location of the alias component depends on the value of (or (match-string-no-properties 5) (match-string-no-properties 3)))) (defun markdown--wiki-link-search-types () + "Return a list of the currently selected search types. + +Due to deprecated variables, as of markdown-mode version 2.5, the return value +of this function is the same as the value of the variable +`markdown-wiki-link-search-type'." (let ((ret (and markdown-wiki-link-search-type (cl-copy-list markdown-wiki-link-search-type)))) (when (and markdown-wiki-link-search-subdirectories @@ -8349,6 +8486,7 @@ The location of the alias component depends on the value of ret)) (defun markdown--project-root () + "Try various approaches to find the project root." (or (cl-loop for dir in '(".git" ".hg" ".svn") when (locate-dominating-file default-directory dir) return it) @@ -8363,17 +8501,14 @@ The location of the alias component depends on the value of (defun markdown-convert-wiki-link-to-filename (name) "Generate a filename from the wiki link NAME. Spaces in NAME are replaced with `markdown-link-space-sub-char'. +Search depth is determined by `markdown-wiki-link-search-type'. When in `gfm-mode', follow GitHub's conventions where [[Test Test]] -and [[test test]] both map to Test-test.ext. Look in the current -directory first, then in subdirectories if -`markdown-wiki-link-search-subdirectories' is non-nil, and then -in parent directories if -`markdown-wiki-link-search-parent-directories' is non-nil." +and [[test test]] both map to Test-test.ext." (save-match-data ;; This function must not overwrite match data(PR #590) (let* ((basename (replace-regexp-in-string "[[:space:]\n]" markdown-link-space-sub-char name)) - (basename (if (derived-mode-p 'gfm-mode) + (basename (if (and (derived-mode-p 'gfm-mode) (not markdown-wiki-link-retain-case)) (concat (upcase (substring basename 0 1)) (downcase (substring basename 1 nil))) basename)) @@ -8459,11 +8594,12 @@ and highlight accordingly." (file-name (markdown-convert-wiki-link-to-filename (markdown-wiki-link-link)))) - (if (condition-case nil (file-exists-p file-name) (error nil)) + (with-no-warnings + (if (condition-case nil (file-exists-p file-name) (error nil)) + (markdown-highlight-wiki-link + highlight-beginning highlight-end 'markdown-link-face) (markdown-highlight-wiki-link - highlight-beginning highlight-end 'markdown-link-face) - (markdown-highlight-wiki-link - highlight-beginning highlight-end 'markdown-missing-link-face))))))) + highlight-beginning highlight-end 'markdown-missing-link-face)))))))) (defun markdown-extend-changed-region (from to) "Extend region given by FROM and TO so that we can fontify all links. @@ -8499,7 +8635,8 @@ newline after." ;; Extend the region to fontify so that it starts ;; and ends at safe places. (cl-multiple-value-bind (new-from new-to) - (markdown-extend-changed-region from to) + (with-no-warnings + (markdown-extend-changed-region from to)) (goto-char new-from) ;; Only refontify when the range contains text with a ;; wiki link face or if the wiki link regexp matches. @@ -8508,10 +8645,11 @@ newline after." '(markdown-link-face markdown-missing-link-face)) (re-search-forward markdown-regex-wiki-link new-to t)) - ;; Unfontify existing fontification (start from scratch) - (markdown-unfontify-region-wiki-links new-from new-to) - ;; Now do the fontification. - (markdown-fontify-region-wiki-links new-from new-to)))))) + (with-no-warnings + ;; Unfontify existing fontification (start from scratch) + (markdown-unfontify-region-wiki-links new-from new-to) + ;; Now do the fontification. + (markdown-fontify-region-wiki-links new-from new-to))))))) (cursor-intangible-mode -1) (and (not modified) (buffer-modified-p) @@ -8520,12 +8658,14 @@ newline after." (defun markdown-check-change-for-wiki-link-after-change (from to _) "Check region between FROM and TO for wiki links and re-fontify as needed. Designed to be used with the `after-change-functions' hook." - (markdown-check-change-for-wiki-link from to)) + (with-no-warnings + (markdown-check-change-for-wiki-link from to))) (defun markdown-fontify-buffer-wiki-links () "Refontify all wiki links in the buffer." (interactive) - (markdown-check-change-for-wiki-link (point-min) (point-max))) + (with-no-warnings + (markdown-check-change-for-wiki-link (point-min) (point-max)))) (defun markdown-toggle-wiki-links (&optional arg) "Toggle support for wiki links. @@ -8537,33 +8677,36 @@ and disable it otherwise." (not markdown-enable-wiki-links) (> (prefix-numeric-value arg) 0))) (when (called-interactively-p 'interactive) - (message "markdown-mode wiki link support %s" (if markdown-enable-wiki-links "enabled" "disabled"))) + (message "markdown-mode wiki link support %s" + (if markdown-enable-wiki-links "enabled" "disabled"))) (markdown-reload-extensions)) (defun markdown-setup-wiki-link-hooks () "Add or remove hooks for fontifying wiki links. These are only enabled when `markdown-wiki-link-fontify-missing' is non-nil." ;; Anytime text changes make sure it gets fontified correctly - (if (and markdown-enable-wiki-links - markdown-wiki-link-fontify-missing) - (add-hook 'after-change-functions - #'markdown-check-change-for-wiki-link-after-change t t) - (remove-hook 'after-change-functions - #'markdown-check-change-for-wiki-link-after-change t)) - ;; If we left the buffer there is a really good chance we were - ;; creating one of the wiki link documents. Make sure we get - ;; refontified when we come back. - (if (and markdown-enable-wiki-links - markdown-wiki-link-fontify-missing) - (progn - (add-hook 'window-configuration-change-hook - #'markdown-fontify-buffer-wiki-links t t) - (markdown-fontify-buffer-wiki-links)) - (remove-hook 'window-configuration-change-hook - #'markdown-fontify-buffer-wiki-links t) - (markdown-unfontify-region-wiki-links (point-min) (point-max)))) + (with-no-warnings + (if (and markdown-enable-wiki-links + markdown-wiki-link-fontify-missing) + (add-hook 'after-change-functions + #'markdown-check-change-for-wiki-link-after-change t t) + (remove-hook 'after-change-functions + #'markdown-check-change-for-wiki-link-after-change t)) + ;; If we left the buffer there is a really good chance we were + ;; creating one of the wiki link documents. Make sure we get + ;; refontified when we come back. + (if (and markdown-enable-wiki-links + markdown-wiki-link-fontify-missing) + (progn + (add-hook 'window-configuration-change-hook + #'markdown-fontify-buffer-wiki-links t t) + (markdown-fontify-buffer-wiki-links)) + (remove-hook 'window-configuration-change-hook + #'markdown-fontify-buffer-wiki-links t) + (with-no-warnings + (markdown-unfontify-region-wiki-links (point-min) (point-max))))) ) + - ;;; Following & Doing ========================================================= (defun markdown-follow-thing-at-point (arg) @@ -8750,9 +8893,7 @@ or span." (interactive) (when (derived-mode-p 'markdown-mode) ;; Refontify buffer - (font-lock-flush) - ;; Add or remove hooks related to extensions - (markdown-setup-wiki-link-hooks))) + (font-lock-flush))) (defun markdown-handle-local-variables () "Run in `hack-local-variables-hook' to update font lock rules. @@ -9091,6 +9232,10 @@ LANG is a string, and the returned major mode is a symbol." (and mode (fboundp mode) (or + (not (string-match-p "ts-mode\\'" (symbol-name mode))) + ;; Don't load tree-sitter mode if the mode is in neither auto-mode-alist nor major-mode-remap-alist + ;; Because some ts-mode overwrites auto-mode-alist and it might break user configurations + ;; https://github.com/jrblevin/markdown-mode/issues/787 ;; major-mode-remap-alist was introduced at Emacs 29.1 (cl-loop for pair in (bound-and-true-p major-mode-remap-alist) @@ -9875,12 +10020,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) @@ -10056,6 +10197,19 @@ rows and columns and the column alignment." (propertize link 'face 'markdown-reference-face) (propertize "]" 'face 'markdown-markup-face)) (propertize link 'face 'markdown-url-face))))) + ;; Hidden URL for wiki links + ((and (and markdown-enable-wiki-links + (thing-at-point-looking-at markdown-regex-wiki-link)) + (or markdown-hide-urls markdown-hide-markup)) + (let* ((aliasp (string-equal (match-string-no-properties 4) "|")) + (part1 (match-string-no-properties 3)) + (part2 (match-string-no-properties 5)) + (link (if (and aliasp markdown-wiki-link-alias-first) part2 part1)) + (edit-keys (markdown--substitute-command-keys + "\\[markdown-insert-wiki-link]")) + (edit-str (propertize edit-keys 'face 'font-lock-constant-face))) + (format "Hidden URL (%s to edit): %s" + edit-str (propertize link 'face 'markdown-reference-face)))) ;; Hidden language name for fenced code blocks ((and (markdown-code-block-at-point-p) (not (get-text-property (point) 'markdown-pre)) @@ -10096,18 +10250,50 @@ 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))) + (dolist (url urls) + (markdown--dnd-local-file-handler url action) + (when multile-urls-p + (insert " "))))) + +(put 'markdown--dnd-multi-local-file-handler 'dnd-multiple-handler t) ;;; Mode Definition ========================================================== @@ -10158,17 +10344,15 @@ rows and columns and the column alignment." (if markdown-hide-markup (add-to-invisibility-spec 'markdown-markup) (remove-from-invisibility-spec 'markdown-markup)) - ;; Wiki links - (markdown-setup-wiki-link-hooks) ;; Math mode (when markdown-enable-math (markdown-toggle-math t)) ;; Add a buffer-local hook to reload after file-local variables are read (add-hook 'hack-local-variables-hook #'markdown-handle-local-variables nil t) ;; For imenu support - (setq imenu-create-index-function - (if markdown-nested-imenu-heading-index - #'markdown-imenu-create-nested-index - #'markdown-imenu-create-flat-index)) + (setq-local imenu-create-index-function (if markdown-nested-imenu-heading-index + #'markdown-imenu-create-nested-index + #'markdown-imenu-create-flat-index) + imenu-submenus-on-top nil) ;; Defun movement (setq-local beginning-of-defun-function #'markdown-beginning-of-defun) @@ -10238,8 +10422,14 @@ rows and columns and the column alignment." #'markdown--inhibit-electric-quote nil :local) ;; drag and drop handler - (setq-local dnd-protocol-alist (cons '("^file:///" . markdown--dnd-local-file-handler) - dnd-protocol-alist)) + (let ((dnd-handler (if (>= emacs-major-version 30) + #'markdown--dnd-multi-local-file-handler + #'markdown--dnd-local-file-handler))) + (setq-local dnd-protocol-alist (append + (list (cons "^file:///" dnd-handler) + (cons "^file:/[^/]" dnd-handler) + (cons "^file:[^/]" dnd-handler)) + dnd-protocol-alist))) ;; media handler (when (version< "29" emacs-version) -- 2.47.3