From 4efa8ef4d3617973b2883605461ffa514675e5b2 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Wed, 22 Jun 2022 16:47:41 +0200 Subject: Update markdown-mode --- .emacs.d/lisp/markdown-mode.el | 136 +++++++++++++++++++++++++---------------- 1 file changed, 85 insertions(+), 51 deletions(-) (limited to '.emacs.d/lisp') diff --git a/.emacs.d/lisp/markdown-mode.el b/.emacs.d/lisp/markdown-mode.el index 009eed3..2162e4f 100644 --- a/.emacs.d/lisp/markdown-mode.el +++ b/.emacs.d/lisp/markdown-mode.el @@ -1,13 +1,13 @@ ;;; markdown-mode.el --- Major mode for Markdown-formatted text -*- lexical-binding: t; -*- -;; Copyright (C) 2007-2020 Jason R. Blevins and markdown-mode +;; Copyright (C) 2007-2022 Jason R. Blevins and markdown-mode ;; contributors (see the commit log for details). ;; Author: Jason R. Blevins ;; Maintainer: Jason R. Blevins ;; Created: May 24, 2007 -;; Version: 2.5-dev -;; Package-Requires: ((emacs "25.1")) +;; Version: 2.6-dev +;; Package-Requires: ((emacs "26.1")) ;; Keywords: Markdown, GitHub Flavored Markdown, itex ;; URL: https://jblevins.org/projects/markdown-mode/ @@ -55,7 +55,7 @@ ;;; Constants ================================================================= -(defconst markdown-mode-version "2.5-dev" +(defconst markdown-mode-version "2.6-dev" "Markdown mode version number.") (defconst markdown-output-buffer-name "*markdown-output*" @@ -188,7 +188,7 @@ line around the header title." (defcustom markdown-indent-on-enter t "Determines indentation behavior when pressing \\[newline]. -Possible settings are nil, t, and 'indent-and-new-item. +Possible settings are nil, t, and `indent-and-new-item'. When non-nil, pressing \\[newline] will call `newline-and-indent' to indent the following line according to the context using @@ -196,7 +196,7 @@ to indent the following line according to the context using \\[electric-newline-and-maybe-indent] can still be used to insert a newline without indentation. -When set to 'indent-and-new-item and the point is in a list item +When set to `indent-and-new-item' and the point is in a list item when \\[newline] is pressed, the list will be continued on the next line, where a new item will be inserted. @@ -490,15 +490,15 @@ completion." (defcustom markdown-split-window-direction 'any "Preference for splitting windows for static and live preview. -The default value is 'any, which instructs Emacs to use +The default value is `any', which instructs Emacs to use `split-window-sensibly' to automatically choose how to split windows based on the values of `split-width-threshold' and `split-height-threshold' and the available windows. To force -vertically split (left and right) windows, set this to 'vertical -or 'right. To force horizontally split (top and bottom) windows, -set this to 'horizontal or 'below. +vertically split (left and right) windows, set this to `vertical' +or `right'. To force horizontally split (top and bottom) windows, +set this to `horizontal' or `below'. -If this value is 'any and `display-buffer-alist' is set then +If this value is `any' and `display-buffer-alist' is set then `display-buffer' is used for open buffer function" :group 'markdown :type '(choice (const :tag "Automatic" any) @@ -516,8 +516,8 @@ the buffer." (defcustom markdown-live-preview-delete-export 'delete-on-destroy "Delete exported HTML file when using `markdown-live-preview-export'. -If set to 'delete-on-export, delete on every export. When set to -'delete-on-destroy delete when quitting from command +If set to `delete-on-export', delete on every export. When set to +`delete-on-destroy' delete when quitting from command `markdown-live-preview-mode'. Never delete if set to nil." :group 'markdown :type '(choice @@ -637,6 +637,15 @@ This variable must be set before loading markdown-mode." :safe 'booleanp :package-version '(markdown-mode . "2.5")) +(defcustom markdown-fontify-whole-heading-line nil + "Non-nil means fontify the whole line for headings. +This is useful when setting a background color for the +markdown-header-face-* faces." + :group 'markdown + :type 'boolean + :safe 'booleanp + :package-version '(markdown-mode . "2.5")) + ;;; Markdown-Specific `rx' Macro ============================================== @@ -855,7 +864,7 @@ Group 3 matches the text.") (defconst markdown-regex-wiki-link "\\(?:^\\|[^\\]\\)\\(?1:\\(?2:\\[\\[\\)\\(?3:[^]|]+\\)\\(?:\\(?4:|\\)\\(?5:[^]]+\\)\\)?\\(?6:\\]\\]\\)\\)" "Regular expression for matching wiki links. -This matches typical bracketed [[WikiLinks]] as well as 'aliased' +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'. @@ -1335,7 +1344,7 @@ block construct when it is matched using to the text matching START-REGEX-OR-FUN, END-PROPERTY to END-REGEX-OR-FUN, and MIDDLE-PROPERTY to the text in between the two. The value of *-PROPERTY is the `match-data' when the regexp was matched to the text. In the case of -MIDDLE-PROPERTY, the value is a false match data of the form '(begin end), with +MIDDLE-PROPERTY, the value is a false match data of the form `(begin end)', with begin and end set to the edges of the \"middle\" text. This makes fontification easier.") @@ -1574,6 +1583,13 @@ MIDDLE-BEGIN is the start of the \"middle\" section of the block." (put-text-property close-begin close-end (cl-cadadr fence-spec) close-data)))) +(defun markdown--triple-quote-single-line-p (begin) + (save-excursion + (goto-char begin) + (save-match-data + (and (search-forward "```" nil t) + (search-forward "```" (line-end-position) t))))) + (defun markdown-syntax-propertize-fenced-block-constructs (start end) "Propertize according to `markdown-fenced-block-pairs' from START to END. If unable to propertize an entire block (if the start of a block is within START @@ -1608,7 +1624,8 @@ start which was previously propertized." (while (re-search-forward start-reg end t) ;; we assume the opening constructs take up (only) an entire line, ;; so we re-check the current line - (let* ((cur-line (buffer-substring (point-at-bol) (point-at-eol))) + (let* ((block-start (match-beginning 0)) + (cur-line (buffer-substring (point-at-bol) (point-at-eol))) ;; find entry in `markdown-fenced-block-pairs' corresponding ;; to regex which was matched (correct-entry @@ -1625,18 +1642,20 @@ start which was previously propertized." (cl-caadr correct-entry) (if (and (match-beginning 1) (match-end 1)) (- (match-end 1) (match-beginning 1)) - 0)))) - ;; get correct match data - (save-excursion - (beginning-of-line) - (re-search-forward - (markdown-maybe-funcall-regexp (caar correct-entry)) - (point-at-eol))) - ;; mark starting, even if ending is outside of region - (put-text-property (match-beginning 0) (match-end 0) - (cl-cadar correct-entry) (match-data t)) - (markdown-propertize-end-match - end-reg end correct-entry enclosed-text-start)))))) + 0))) + (prop (cl-cadar correct-entry))) + (when (or (not (eq prop 'markdown-gfm-block-begin)) + (not (markdown--triple-quote-single-line-p block-start))) + ;; get correct match data + (save-excursion + (beginning-of-line) + (re-search-forward + (markdown-maybe-funcall-regexp (caar correct-entry)) + (point-at-eol))) + ;; mark starting, even if ending is outside of region + (put-text-property (match-beginning 0) (match-end 0) prop (match-data t)) + (markdown-propertize-end-match + end-reg end correct-entry enclosed-text-start))))))) (defun markdown-syntax-propertize-blockquotes (start end) "Match blockquotes from START to END." @@ -2218,6 +2237,11 @@ Depending on your font, some reasonable choices are: ;;; Compatibility ============================================================= +(defun markdown--pandoc-reference-p () + (let ((bounds (bounds-of-thing-at-point 'word))) + (when (and bounds (char-before (car bounds))) + (= (char-before (car bounds)) ?@)))) + (defun markdown-flyspell-check-word-p () "Return t if `flyspell' should check word just before point. Used for `flyspell-generic-check-word-predicate'." @@ -2233,7 +2257,8 @@ Used for `flyspell-generic-check-word-predicate'." markdown-markup-face markdown-plain-url-face markdown-inline-code-face - markdown-url-face))) + markdown-url-face)) + (markdown--pandoc-reference-p)) (prog1 nil ;; If flyspell overlay is put, then remove it (let ((bounds (bounds-of-thing-at-point 'word))) @@ -2622,7 +2647,7 @@ The return value has the same form as that of (defun markdown-bounds-of-thing-at-point (thing) "Call `bounds-of-thing-at-point' for THING with slight modifications. -Does not include trailing newlines when THING is 'line. Handles the +Does not include trailing newlines when THING is `line'. Handles the end of buffer case by setting both endpoints equal to the value of `point-max', since an empty region will trigger empty markup insertion. Return bounds of form (beg . end) if THING is found, or nil otherwise." @@ -3003,13 +3028,13 @@ Restore match data previously stored in PROPERTY." (defun markdown-match-pre-blocks (last) "Match preformatted blocks from point to LAST. -Use data stored in 'markdown-pre text property during syntax +Use data stored in `markdown-pre' text property during syntax analysis." (markdown-match-propertized-text 'markdown-pre last)) (defun markdown-match-gfm-code-blocks (last) "Match GFM quoted code blocks from point to LAST. -Use data stored in 'markdown-gfm-code text property during syntax +Use data stored in `markdown-gfm-code' text property during syntax analysis." (markdown-match-propertized-text 'markdown-gfm-code last)) @@ -3031,7 +3056,7 @@ analysis." (defun markdown-match-blockquotes (last) "Match blockquotes from point to LAST. -Use data stored in 'markdown-blockquote text property during syntax +Use data stored in `markdown-blockquote' text property during syntax analysis." (markdown-match-propertized-text 'markdown-blockquote last)) @@ -3416,13 +3441,17 @@ SEQ may be an atom or a sequence." (add-text-properties (match-beginning 3) (match-end 3) rule-props))) ;; atx heading - (add-text-properties - (match-beginning 4) (match-end 4) left-markup-props) - (add-text-properties - (match-beginning 5) (match-end 5) heading-props) - (when (match-end 6) + (if markdown-fontify-whole-heading-line + (let ((header-end (min (point-max) (1+ (match-end 0))))) + (add-text-properties + (match-beginning 0) header-end heading-props)) + (add-text-properties + (match-beginning 4) (match-end 4) left-markup-props) (add-text-properties - (match-beginning 6) (match-end 6) right-markup-props)))) + (match-beginning 5) (match-end 5) heading-props) + (when (match-end 6) + (add-text-properties + (match-beginning 6) (match-end 6) right-markup-props))))) t)) (defun markdown-fontify-tables (last) @@ -4508,7 +4537,7 @@ at the beginning of the block." (defun markdown-insert-foldable-block () "Insert details disclosure element to make content foldable. If a region is active, wrap this region with the disclosure -element. More detais here 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details'." +element. More detais here https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details." (interactive) (let ((details-open-tag "
") (details-close-tag "
") @@ -4953,7 +4982,7 @@ If the point is at a table, move to the next row. Otherwise, indent according to value of `markdown-indent-on-enter'. When it is nil, simply call `newline'. Otherwise, indent the next line following RET using `markdown-indent-line'. Furthermore, when it -is set to 'indent-and-new-item and the point is in a list item, +is set to `indent-and-new-item' and the point is in a list item, start a new item with the same indentation. If the point is in an empty list item, remove it (so that pressing RET twice when in a list simply adds a blank line)." @@ -7341,7 +7370,11 @@ Return the name of the output buffer used." (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)) - (funcall markdown-command begin-region end-region buf) + (if markdown-command-needs-filename + (if (not buffer-file-name) + (user-error "Must be visiting a file") + (funcall markdown-command begin-region end-region buf buffer-file-name)) + (funcall markdown-command begin-region end-region buf)) ;; If the ‘markdown-command’ function didn’t signal an ;; error, assume it succeeded by binding ‘exit-code’ to 0. 0)))))) @@ -7645,20 +7678,19 @@ displaying the rendered output." (setq markdown-live-preview-source-buffer nil)))) (defun markdown-live-preview-switch-to-output () - "Switch to output buffer." + "Turn on `markdown-live-preview-mode' and switch to output buffer. +The output buffer is opened in another window." (interactive) - "Turn on `markdown-live-preview-mode' if not already on, and switch to its -output buffer in another window." (if markdown-live-preview-mode (markdown-display-buffer-other-window (markdown-live-preview-export))) (markdown-live-preview-mode)) (defun markdown-live-preview-re-export () - "Re export source buffer." - (interactive) - "If the current buffer is a buffer displaying the exported version of a + "Re-export the current live previewed content. +If the current buffer is a buffer displaying the exported version of a `markdown-live-preview-mode' buffer, call `markdown-live-preview-export' and update this buffer's contents." + (interactive) (when markdown-live-preview-source-buffer (with-current-buffer markdown-live-preview-source-buffer (markdown-live-preview-export)))) @@ -9636,7 +9668,7 @@ rows and columns and the column alignment." ;;; ElDoc Support ============================================================= -(defun markdown-eldoc-function () +(defun markdown-eldoc-function (&rest _ignored) "Return a helpful string when appropriate based on context. * Report URL when point is at a hidden URL. * Report language name when point is a code block with hidden markup." @@ -9776,8 +9808,10 @@ rows and columns and the column alignment." ;; Cause use of ellipses for invisible text. (add-to-invisibility-spec '(outline . t)) ;; ElDoc support - (add-function :before-until (local 'eldoc-documentation-function) - #'markdown-eldoc-function) + (if (boundp 'eldoc-documentation-functions) + (add-hook 'eldoc-documentation-functions #'markdown-eldoc-function nil t) + (add-function :before-until (local 'eldoc-documentation-function) + #'markdown-eldoc-function)) ;; Inhibiting line-breaking: ;; Separating out each condition into a separate function so that users can ;; override if desired (with remove-hook) -- cgit v1.3