From a773e7ed865a1a7eb5bf00b9f0481e888534831a Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Sat, 9 Nov 2024 13:04:13 +0100 Subject: Upgrade markdown-mode, nginx-mode, rust-mode, yaml-mode and python-mode/property_getter --- .emacs.d/lisp/markdown-mode.el | 262 ++++++++++++++++++++++------------------- 1 file changed, 140 insertions(+), 122 deletions(-) (limited to '.emacs.d/lisp/markdown-mode.el') diff --git a/.emacs.d/lisp/markdown-mode.el b/.emacs.d/lisp/markdown-mode.el index 33f7476..89d8962 100644 --- a/.emacs.d/lisp/markdown-mode.el +++ b/.emacs.d/lisp/markdown-mode.el @@ -684,52 +684,36 @@ This may also be a cons cell where the behavior for `C-a' and `C-e' is set separately." :group 'markdown :type '(choice - (const :tag "off" nil) - (const :tag "on: after hashes/bullet and before closing tags first" t) - (const :tag "reversed: true line boundary first" reversed) - (cons :tag "Set C-a and C-e separately" - (choice :tag "Special C-a" - (const :tag "off" nil) - (const :tag "on: after hashes/bullet first" t) - (const :tag "reversed: before hashes/bullet first" reversed)) - (choice :tag "Special C-e" - (const :tag "off" nil) - (const :tag "on: before closing tags first" t) - (const :tag "reversed: after closing tags first" reversed)))) + (const :tag "off" nil) + (const :tag "on: after hashes/bullet and before closing tags first" t) + (const :tag "reversed: true line boundary first" reversed) + (cons :tag "Set C-a and C-e separately" + (choice :tag "Special C-a" + (const :tag "off" nil) + (const :tag "on: after hashes/bullet first" t) + (const :tag "reversed: before hashes/bullet first" reversed)) + (choice :tag "Special C-e" + (const :tag "off" nil) + (const :tag "on: before closing tags first" t) + (const :tag "reversed: after closing tags first" reversed)))) :package-version '(markdown-mode . "2.7")) ;;; Markdown-Specific `rx' Macro ============================================== ;; Based on python-rx from python.el. -(eval-and-compile - (defconst markdown-rx-constituents - `((newline . ,(rx "\n")) - ;; Note: #405 not consider markdown-list-indent-width however this is never used - (indent . ,(rx (or (repeat 4 " ") "\t"))) - (block-end . ,(rx (and (or (one-or-more (zero-or-more blank) "\n") line-end)))) - (numeral . ,(rx (and (one-or-more (any "0-9#")) "."))) - (bullet . ,(rx (any "*+:-"))) - (list-marker . ,(rx (or (and (one-or-more (any "0-9#")) ".") - (any "*+:-")))) - (checkbox . ,(rx "[" (any " xX") "]"))) - "Markdown-specific sexps for `markdown-rx'") - - (defun markdown-rx-to-string (form &optional no-group) - "Markdown mode specialized `rx-to-string' function. -This variant supports named Markdown expressions in FORM. -NO-GROUP non-nil means don't put shy groups around the result." - (let ((rx-constituents (append markdown-rx-constituents rx-constituents))) - (rx-to-string form no-group))) - - (defmacro markdown-rx (&rest regexps) - "Markdown mode specialized rx macro. +(defmacro markdown-rx (&rest regexps) + "Markdown mode specialized rx macro. This variant of `rx' supports common Markdown named REGEXPS." - (cond ((null regexps) - (error "No regexp")) - ((cdr regexps) - (markdown-rx-to-string `(and ,@regexps) t)) - (t - (markdown-rx-to-string (car regexps) t))))) + `(rx-let ((newline "\n") + ;; Note: #405 not consider markdown-list-indent-width however this is never used + (indent (or (repeat 4 " ") "\t")) + (block-end (and (or (one-or-more (zero-or-more blank) "\n") line-end))) + (numeral (and (one-or-more (any "0-9#")) ".")) + (bullet (any "*+:-")) + (list-marker (or (and (one-or-more (any "0-9#")) ".") + (any "*+:-"))) + (checkbox (seq "[" (any " xX") "]"))) + (rx ,@regexps))) ;;; Regular Expressions ======================================================= @@ -1157,7 +1141,8 @@ Group 4 matches the text inside the delimiters.") "Property list of all Markdown syntactic properties.") (defvar markdown-literal-faces - '(markdown-inline-code-face + '(markdown-code-face + markdown-inline-code-face markdown-pre-face markdown-math-face markdown-url-face @@ -2804,8 +2789,9 @@ They does not include square brackets)." uris :test #'equal))) (reverse uris)))) -(defun markdown-inline-code-at-pos (pos) - "Return non-nil if there is an inline code fragment at POS. +(defun markdown-inline-code-at-pos (pos &optional from) + "Return non-nil if there is an inline code fragment at POS starting at FROM. +Uses the beginning of the block if FROM is nil. Return nil otherwise. Set match data according to `markdown-match-code' upon success. This function searches the block for a code fragment that @@ -2822,7 +2808,9 @@ Group 3 matches the closing backquotes." (let ((old-point (point)) (end-of-block (progn (markdown-end-of-text-block) (point))) found) - (markdown-beginning-of-text-block) + (if from + (goto-char from) + (markdown-beginning-of-text-block)) (while (and (markdown-match-code end-of-block) (setq found t) (< (match-end 0) old-point))) @@ -2970,28 +2958,42 @@ When FACELESS is non-nil, do not return matches where faces have been applied." (defun markdown-match-bold (last) "Match inline bold from the point to LAST." - (when (markdown-match-inline-generic markdown-regex-bold last) - (let ((is-gfm (derived-mode-p 'gfm-mode)) - (begin (match-beginning 2)) - (end (match-end 2))) - (if (or (markdown-inline-code-at-pos-p begin) - (markdown-inline-code-at-pos-p end) - (markdown-in-comment-p) - (markdown-range-property-any - begin begin 'face '(markdown-url-face - markdown-plain-url-face)) - (markdown-range-property-any - begin end 'face '(markdown-hr-face - markdown-math-face)) - (and is-gfm (not (markdown--gfm-markup-underscore-p begin end)))) - (progn (goto-char (min (1+ begin) last)) - (when (< (point) last) - (markdown-match-bold last))) - (set-match-data (list (match-beginning 2) (match-end 2) - (match-beginning 3) (match-end 3) - (match-beginning 4) (match-end 4) - (match-beginning 5) (match-end 5))) - t)))) + (let (done + retval + last-inline-code) + (while (not done) + (if (markdown-match-inline-generic markdown-regex-bold last) + (let ((is-gfm (derived-mode-p 'gfm-mode)) + (begin (match-beginning 2)) + (end (match-end 2))) + (if (or + (and last-inline-code + (>= begin (car last-inline-code)) + (< begin (cdr last-inline-code))) + (save-match-data + (when (markdown-inline-code-at-pos begin (cdr last-inline-code)) + (setq last-inline-code `(,(match-beginning 0) . ,(match-end 0))))) + (markdown-inline-code-at-pos-p end) + (markdown-in-comment-p) + (markdown-range-property-any + begin begin 'face '(markdown-url-face + markdown-plain-url-face)) + (markdown-range-property-any + begin end 'face '(markdown-hr-face + markdown-math-face)) + (and is-gfm (not (markdown--gfm-markup-underscore-p begin end)))) + (progn (goto-char (min (1+ begin) last)) + (unless (< (point) last) + (setq + done t))) + (set-match-data (list (match-beginning 2) (match-end 2) + (match-beginning 3) (match-end 3) + (match-beginning 4) (match-end 4) + (match-beginning 5) (match-end 5))) + (setq done t + retval t))) + (setq done t))) + retval)) (defun markdown-match-italic (last) "Match inline italics from the point to LAST." @@ -2999,37 +3001,51 @@ When FACELESS is non-nil, do not return matches where faces have been applied." (regex (if is-gfm markdown-regex-gfm-italic markdown-regex-italic))) - (when (and (markdown-match-inline-generic regex last) - (not (markdown--face-p - (match-beginning 1) - '(markdown-html-attr-name-face markdown-html-attr-value-face)))) - (let ((begin (match-beginning 1)) - (end (match-end 1)) - (close-end (match-end 4))) - (if (or (eql (char-before begin) (char-after begin)) - (markdown-inline-code-at-pos-p begin) - (markdown-inline-code-at-pos-p (1- end)) - (markdown-in-comment-p) - (markdown-range-property-any - begin begin 'face '(markdown-url-face - markdown-plain-url-face - markdown-markup-face)) - (markdown-range-property-any - begin end 'face '(markdown-bold-face - markdown-list-face - markdown-hr-face - markdown-math-face)) - (and is-gfm - (or (char-equal (char-after begin) (char-after (1+ begin))) ;; check bold case - (not (markdown--gfm-markup-underscore-p begin close-end))))) - (progn (goto-char (min (1+ begin) last)) - (when (< (point) last) - (markdown-match-italic last))) - (set-match-data (list (match-beginning 1) (match-end 1) - (match-beginning 2) (match-end 2) - (match-beginning 3) (match-end 3) - (match-beginning 4) (match-end 4))) - t))))) + (let (done + retval + last-inline-code) + (while (not done) + (if (and (markdown-match-inline-generic regex last) + (not (markdown--face-p + (match-beginning 1) + '(markdown-html-attr-name-face markdown-html-attr-value-face)))) + (let ((begin (match-beginning 1)) + (end (match-end 1)) + (close-end (match-end 4))) + (if (or (eql (char-before begin) (char-after begin)) + (and last-inline-code + (>= begin (car last-inline-code)) + (< begin (cdr last-inline-code))) + (save-match-data + (when (markdown-inline-code-at-pos begin (cdr last-inline-code)) + (setq last-inline-code `(,(match-beginning 0) . ,(match-end 0))))) + + (markdown-inline-code-at-pos-p (1- end)) + (markdown-in-comment-p) + (markdown-range-property-any + begin begin 'face '(markdown-url-face + markdown-plain-url-face + markdown-markup-face)) + (markdown-range-property-any + begin end 'face '(markdown-bold-face + markdown-list-face + markdown-hr-face + markdown-math-face)) + (and is-gfm + (or (char-equal (char-after begin) (char-after (1+ begin))) ;; check bold case + (not (markdown--gfm-markup-underscore-p begin close-end))))) + (progn (goto-char (min (1+ begin) last)) + (unless (< (point) last) + (setq + done t))) + (set-match-data (list (match-beginning 1) (match-end 1) + (match-beginning 2) (match-end 2) + (match-beginning 3) (match-end 3) + (match-beginning 4) (match-end 4))) + (setq done t + retval t))) + (setq done t))) + retval))) (defun markdown--match-highlighting (last) (when markdown-enable-highlighting-syntax @@ -3543,30 +3559,25 @@ SEQ may be an atom or a sequence." (add-text-properties (match-beginning 3) (match-end 3) rule-props))) ;; atx heading - (let ((header-end + (let ((fontified-start + (if (or markdown-hide-markup (not markdown-fontify-whole-heading-line)) + (match-beginning 5) + (match-beginning 0))) + (fontified-end (if markdown-fontify-whole-heading-line (min (point-max) (1+ (match-end 0))) - (match-end 0)))) + (match-end 5)))) (add-text-properties (match-beginning 4) (match-end 4) left-markup-props) ;; If closing tag is present (if (match-end 6) (progn - (if markdown-hide-markup - (progn - (add-text-properties - (match-beginning 5) header-end heading-props) - (add-text-properties - (match-beginning 6) (match-end 6) right-markup-props)) - (add-text-properties - (match-beginning 5) (match-end 5) heading-props) - (add-text-properties - (match-beginning 6) header-end right-markup-props))) + (add-text-properties fontified-start fontified-end heading-props) + (when (or markdown-hide-markup (not markdown-fontify-whole-heading-line)) + (add-text-properties (match-beginning 6) (match-end 6) right-markup-props))) ;; If closing tag is not present - (add-text-properties - (match-beginning 5) header-end heading-props)) - ))) + (add-text-properties fontified-start fontified-end heading-props))))) t)) (defun markdown-fontify-tables (last) @@ -3812,12 +3823,12 @@ prefixed with an integer from 1 to the length of (when (and beg skip-space) (save-excursion (goto-char beg) - (skip-chars-forward "[ \t]") + (skip-chars-forward " \t") (setq beg (point)))) (when (and end skip-space) (save-excursion (goto-char end) - (skip-chars-backward "[ \t]") + (skip-chars-backward " \t") (setq end (point)))) (markdown-wrap-or-insert start-delim end-delim nil beg end)) (if (markdown--face-p (point) (list face)) @@ -4894,7 +4905,7 @@ footnote text is found, NIL is returned." (save-excursion (goto-char (point-min)) (when (re-search-forward (concat "^ \\{0,3\\}\\[" id "\\]:") nil t) - (skip-chars-forward "[ \t]") + (skip-chars-forward " \t") (point)))) (defun markdown-footnote-marker-positions () @@ -7692,12 +7703,14 @@ Return the name of the output buffer used." Insert the output in the buffer named OUTPUT-BUFFER-NAME." (interactive) (setq output-buffer-name (markdown output-buffer-name)) - (with-current-buffer output-buffer-name - (set-buffer output-buffer-name) - (unless (markdown-output-standalone-p) - (markdown-add-xhtml-header-and-footer output-buffer-name)) - (goto-char (point-min)) - (html-mode)) + (let ((css-path markdown-css-paths)) + (with-current-buffer output-buffer-name + (set-buffer output-buffer-name) + (setq-local markdown-css-paths css-path) + (unless (markdown-output-standalone-p) + (markdown-add-xhtml-header-and-footer output-buffer-name)) + (goto-char (point-min)) + (html-mode))) output-buffer-name) (defun markdown-other-window (&optional output-buffer-name) @@ -9139,7 +9152,7 @@ position." (remove-text-properties start end '(face nil)) (with-current-buffer (get-buffer-create - (concat " markdown-code-fontification:" (symbol-name lang-mode))) + (format " *markdown-code-fontification:%s*" (symbol-name lang-mode))) ;; Make sure that modification hooks are not inhibited in ;; the org-src-fontification buffer in case we're called ;; from `jit-lock-function' (Bug#25132). @@ -10292,6 +10305,11 @@ rows and columns and the column alignment." (setq markdown-link-space-sub-char "-") (setq markdown-wiki-link-search-subdirectories t) (setq-local markdown-table-at-point-p-function #'gfm--table-at-point-p) + (setq-local paragraph-separate + (concat paragraph-separate + "\\|" + ;; GFM alert syntax + "^>\s-*\\[!\\(?:NOTE\\|TIP\\|IMPORTANT\\|WARNING\\|CAUTION\\)\\]")) (add-hook 'post-self-insert-hook #'gfm--electric-pair-fence-code-block 'append t) (markdown-gfm-parse-buffer-for-languages)) -- cgit v1.3