diff options
Diffstat (limited to '.emacs.d/lisp/markdown-mode.el')
| -rw-r--r-- | .emacs.d/lisp/markdown-mode.el | 262 |
1 files changed, 140 insertions, 122 deletions
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 | |||
| 684 | `C-e' is set separately." | 684 | `C-e' is set separately." |
| 685 | :group 'markdown | 685 | :group 'markdown |
| 686 | :type '(choice | 686 | :type '(choice |
| 687 | (const :tag "off" nil) | 687 | (const :tag "off" nil) |
| 688 | (const :tag "on: after hashes/bullet and before closing tags first" t) | 688 | (const :tag "on: after hashes/bullet and before closing tags first" t) |
| 689 | (const :tag "reversed: true line boundary first" reversed) | 689 | (const :tag "reversed: true line boundary first" reversed) |
| 690 | (cons :tag "Set C-a and C-e separately" | 690 | (cons :tag "Set C-a and C-e separately" |
| 691 | (choice :tag "Special C-a" | 691 | (choice :tag "Special C-a" |
| 692 | (const :tag "off" nil) | 692 | (const :tag "off" nil) |
| 693 | (const :tag "on: after hashes/bullet first" t) | 693 | (const :tag "on: after hashes/bullet first" t) |
| 694 | (const :tag "reversed: before hashes/bullet first" reversed)) | 694 | (const :tag "reversed: before hashes/bullet first" reversed)) |
| 695 | (choice :tag "Special C-e" | 695 | (choice :tag "Special C-e" |
| 696 | (const :tag "off" nil) | 696 | (const :tag "off" nil) |
| 697 | (const :tag "on: before closing tags first" t) | 697 | (const :tag "on: before closing tags first" t) |
| 698 | (const :tag "reversed: after closing tags first" reversed)))) | 698 | (const :tag "reversed: after closing tags first" reversed)))) |
| 699 | :package-version '(markdown-mode . "2.7")) | 699 | :package-version '(markdown-mode . "2.7")) |
| 700 | 700 | ||
| 701 | ;;; Markdown-Specific `rx' Macro ============================================== | 701 | ;;; Markdown-Specific `rx' Macro ============================================== |
| 702 | 702 | ||
| 703 | ;; Based on python-rx from python.el. | 703 | ;; Based on python-rx from python.el. |
| 704 | (eval-and-compile | 704 | (defmacro markdown-rx (&rest regexps) |
| 705 | (defconst markdown-rx-constituents | 705 | "Markdown mode specialized rx macro. |
| 706 | `((newline . ,(rx "\n")) | ||
| 707 | ;; Note: #405 not consider markdown-list-indent-width however this is never used | ||
| 708 | (indent . ,(rx (or (repeat 4 " ") "\t"))) | ||
| 709 | (block-end . ,(rx (and (or (one-or-more (zero-or-more blank) "\n") line-end)))) | ||
| 710 | (numeral . ,(rx (and (one-or-more (any "0-9#")) "."))) | ||
| 711 | (bullet . ,(rx (any "*+:-"))) | ||
| 712 | (list-marker . ,(rx (or (and (one-or-more (any "0-9#")) ".") | ||
| 713 | (any "*+:-")))) | ||
| 714 | (checkbox . ,(rx "[" (any " xX") "]"))) | ||
| 715 | "Markdown-specific sexps for `markdown-rx'") | ||
| 716 | |||
| 717 | (defun markdown-rx-to-string (form &optional no-group) | ||
| 718 | "Markdown mode specialized `rx-to-string' function. | ||
| 719 | This variant supports named Markdown expressions in FORM. | ||
| 720 | NO-GROUP non-nil means don't put shy groups around the result." | ||
| 721 | (let ((rx-constituents (append markdown-rx-constituents rx-constituents))) | ||
| 722 | (rx-to-string form no-group))) | ||
| 723 | |||
| 724 | (defmacro markdown-rx (&rest regexps) | ||
| 725 | "Markdown mode specialized rx macro. | ||
| 726 | This variant of `rx' supports common Markdown named REGEXPS." | 706 | This variant of `rx' supports common Markdown named REGEXPS." |
| 727 | (cond ((null regexps) | 707 | `(rx-let ((newline "\n") |
| 728 | (error "No regexp")) | 708 | ;; Note: #405 not consider markdown-list-indent-width however this is never used |
| 729 | ((cdr regexps) | 709 | (indent (or (repeat 4 " ") "\t")) |
| 730 | (markdown-rx-to-string `(and ,@regexps) t)) | 710 | (block-end (and (or (one-or-more (zero-or-more blank) "\n") line-end))) |
| 731 | (t | 711 | (numeral (and (one-or-more (any "0-9#")) ".")) |
| 732 | (markdown-rx-to-string (car regexps) t))))) | 712 | (bullet (any "*+:-")) |
| 713 | (list-marker (or (and (one-or-more (any "0-9#")) ".") | ||
| 714 | (any "*+:-"))) | ||
| 715 | (checkbox (seq "[" (any " xX") "]"))) | ||
| 716 | (rx ,@regexps))) | ||
| 733 | 717 | ||
| 734 | 718 | ||
| 735 | ;;; Regular Expressions ======================================================= | 719 | ;;; Regular Expressions ======================================================= |
| @@ -1157,7 +1141,8 @@ Group 4 matches the text inside the delimiters.") | |||
| 1157 | "Property list of all Markdown syntactic properties.") | 1141 | "Property list of all Markdown syntactic properties.") |
| 1158 | 1142 | ||
| 1159 | (defvar markdown-literal-faces | 1143 | (defvar markdown-literal-faces |
| 1160 | '(markdown-inline-code-face | 1144 | '(markdown-code-face |
| 1145 | markdown-inline-code-face | ||
| 1161 | markdown-pre-face | 1146 | markdown-pre-face |
| 1162 | markdown-math-face | 1147 | markdown-math-face |
| 1163 | markdown-url-face | 1148 | markdown-url-face |
| @@ -2804,8 +2789,9 @@ They does not include square brackets)." | |||
| 2804 | uris :test #'equal))) | 2789 | uris :test #'equal))) |
| 2805 | (reverse uris)))) | 2790 | (reverse uris)))) |
| 2806 | 2791 | ||
| 2807 | (defun markdown-inline-code-at-pos (pos) | 2792 | (defun markdown-inline-code-at-pos (pos &optional from) |
| 2808 | "Return non-nil if there is an inline code fragment at POS. | 2793 | "Return non-nil if there is an inline code fragment at POS starting at FROM. |
| 2794 | Uses the beginning of the block if FROM is nil. | ||
| 2809 | Return nil otherwise. Set match data according to | 2795 | Return nil otherwise. Set match data according to |
| 2810 | `markdown-match-code' upon success. | 2796 | `markdown-match-code' upon success. |
| 2811 | This function searches the block for a code fragment that | 2797 | This function searches the block for a code fragment that |
| @@ -2822,7 +2808,9 @@ Group 3 matches the closing backquotes." | |||
| 2822 | (let ((old-point (point)) | 2808 | (let ((old-point (point)) |
| 2823 | (end-of-block (progn (markdown-end-of-text-block) (point))) | 2809 | (end-of-block (progn (markdown-end-of-text-block) (point))) |
| 2824 | found) | 2810 | found) |
| 2825 | (markdown-beginning-of-text-block) | 2811 | (if from |
| 2812 | (goto-char from) | ||
| 2813 | (markdown-beginning-of-text-block)) | ||
| 2826 | (while (and (markdown-match-code end-of-block) | 2814 | (while (and (markdown-match-code end-of-block) |
| 2827 | (setq found t) | 2815 | (setq found t) |
| 2828 | (< (match-end 0) old-point))) | 2816 | (< (match-end 0) old-point))) |
| @@ -2970,28 +2958,42 @@ When FACELESS is non-nil, do not return matches where faces have been applied." | |||
| 2970 | 2958 | ||
| 2971 | (defun markdown-match-bold (last) | 2959 | (defun markdown-match-bold (last) |
| 2972 | "Match inline bold from the point to LAST." | 2960 | "Match inline bold from the point to LAST." |
| 2973 | (when (markdown-match-inline-generic markdown-regex-bold last) | 2961 | (let (done |
| 2974 | (let ((is-gfm (derived-mode-p 'gfm-mode)) | 2962 | retval |
| 2975 | (begin (match-beginning 2)) | 2963 | last-inline-code) |
| 2976 | (end (match-end 2))) | 2964 | (while (not done) |
| 2977 | (if (or (markdown-inline-code-at-pos-p begin) | 2965 | (if (markdown-match-inline-generic markdown-regex-bold last) |
| 2978 | (markdown-inline-code-at-pos-p end) | 2966 | (let ((is-gfm (derived-mode-p 'gfm-mode)) |
| 2979 | (markdown-in-comment-p) | 2967 | (begin (match-beginning 2)) |
| 2980 | (markdown-range-property-any | 2968 | (end (match-end 2))) |
| 2981 | begin begin 'face '(markdown-url-face | 2969 | (if (or |
| 2982 | markdown-plain-url-face)) | 2970 | (and last-inline-code |
| 2983 | (markdown-range-property-any | 2971 | (>= begin (car last-inline-code)) |
| 2984 | begin end 'face '(markdown-hr-face | 2972 | (< begin (cdr last-inline-code))) |
| 2985 | markdown-math-face)) | 2973 | (save-match-data |
| 2986 | (and is-gfm (not (markdown--gfm-markup-underscore-p begin end)))) | 2974 | (when (markdown-inline-code-at-pos begin (cdr last-inline-code)) |
| 2987 | (progn (goto-char (min (1+ begin) last)) | 2975 | (setq last-inline-code `(,(match-beginning 0) . ,(match-end 0))))) |
| 2988 | (when (< (point) last) | 2976 | (markdown-inline-code-at-pos-p end) |
| 2989 | (markdown-match-bold last))) | 2977 | (markdown-in-comment-p) |
| 2990 | (set-match-data (list (match-beginning 2) (match-end 2) | 2978 | (markdown-range-property-any |
| 2991 | (match-beginning 3) (match-end 3) | 2979 | begin begin 'face '(markdown-url-face |
| 2992 | (match-beginning 4) (match-end 4) | 2980 | markdown-plain-url-face)) |
| 2993 | (match-beginning 5) (match-end 5))) | 2981 | (markdown-range-property-any |
| 2994 | t)))) | 2982 | begin end 'face '(markdown-hr-face |
| 2983 | markdown-math-face)) | ||
| 2984 | (and is-gfm (not (markdown--gfm-markup-underscore-p begin end)))) | ||
| 2985 | (progn (goto-char (min (1+ begin) last)) | ||
| 2986 | (unless (< (point) last) | ||
| 2987 | (setq | ||
| 2988 | done t))) | ||
| 2989 | (set-match-data (list (match-beginning 2) (match-end 2) | ||
| 2990 | (match-beginning 3) (match-end 3) | ||
| 2991 | (match-beginning 4) (match-end 4) | ||
| 2992 | (match-beginning 5) (match-end 5))) | ||
| 2993 | (setq done t | ||
| 2994 | retval t))) | ||
| 2995 | (setq done t))) | ||
| 2996 | retval)) | ||
| 2995 | 2997 | ||
| 2996 | (defun markdown-match-italic (last) | 2998 | (defun markdown-match-italic (last) |
| 2997 | "Match inline italics from the point to LAST." | 2999 | "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." | |||
| 2999 | (regex (if is-gfm | 3001 | (regex (if is-gfm |
| 3000 | markdown-regex-gfm-italic | 3002 | markdown-regex-gfm-italic |
| 3001 | markdown-regex-italic))) | 3003 | markdown-regex-italic))) |
| 3002 | (when (and (markdown-match-inline-generic regex last) | 3004 | (let (done |
| 3003 | (not (markdown--face-p | 3005 | retval |
| 3004 | (match-beginning 1) | 3006 | last-inline-code) |
| 3005 | '(markdown-html-attr-name-face markdown-html-attr-value-face)))) | 3007 | (while (not done) |
| 3006 | (let ((begin (match-beginning 1)) | 3008 | (if (and (markdown-match-inline-generic regex last) |
| 3007 | (end (match-end 1)) | 3009 | (not (markdown--face-p |
| 3008 | (close-end (match-end 4))) | 3010 | (match-beginning 1) |
| 3009 | (if (or (eql (char-before begin) (char-after begin)) | 3011 | '(markdown-html-attr-name-face markdown-html-attr-value-face)))) |
| 3010 | (markdown-inline-code-at-pos-p begin) | 3012 | (let ((begin (match-beginning 1)) |
| 3011 | (markdown-inline-code-at-pos-p (1- end)) | 3013 | (end (match-end 1)) |
| 3012 | (markdown-in-comment-p) | 3014 | (close-end (match-end 4))) |
| 3013 | (markdown-range-property-any | 3015 | (if (or (eql (char-before begin) (char-after begin)) |
| 3014 | begin begin 'face '(markdown-url-face | 3016 | (and last-inline-code |
| 3015 | markdown-plain-url-face | 3017 | (>= begin (car last-inline-code)) |
| 3016 | markdown-markup-face)) | 3018 | (< begin (cdr last-inline-code))) |
| 3017 | (markdown-range-property-any | 3019 | (save-match-data |
| 3018 | begin end 'face '(markdown-bold-face | 3020 | (when (markdown-inline-code-at-pos begin (cdr last-inline-code)) |
| 3019 | markdown-list-face | 3021 | (setq last-inline-code `(,(match-beginning 0) . ,(match-end 0))))) |
| 3020 | markdown-hr-face | 3022 | |
| 3021 | markdown-math-face)) | 3023 | (markdown-inline-code-at-pos-p (1- end)) |
| 3022 | (and is-gfm | 3024 | (markdown-in-comment-p) |
| 3023 | (or (char-equal (char-after begin) (char-after (1+ begin))) ;; check bold case | 3025 | (markdown-range-property-any |
| 3024 | (not (markdown--gfm-markup-underscore-p begin close-end))))) | 3026 | begin begin 'face '(markdown-url-face |
| 3025 | (progn (goto-char (min (1+ begin) last)) | 3027 | markdown-plain-url-face |
| 3026 | (when (< (point) last) | 3028 | markdown-markup-face)) |
| 3027 | (markdown-match-italic last))) | 3029 | (markdown-range-property-any |
| 3028 | (set-match-data (list (match-beginning 1) (match-end 1) | 3030 | begin end 'face '(markdown-bold-face |
| 3029 | (match-beginning 2) (match-end 2) | 3031 | markdown-list-face |
| 3030 | (match-beginning 3) (match-end 3) | 3032 | markdown-hr-face |
| 3031 | (match-beginning 4) (match-end 4))) | 3033 | markdown-math-face)) |
| 3032 | t))))) | 3034 | (and is-gfm |
| 3035 | (or (char-equal (char-after begin) (char-after (1+ begin))) ;; check bold case | ||
| 3036 | (not (markdown--gfm-markup-underscore-p begin close-end))))) | ||
| 3037 | (progn (goto-char (min (1+ begin) last)) | ||
| 3038 | (unless (< (point) last) | ||
| 3039 | (setq | ||
| 3040 | done t))) | ||
| 3041 | (set-match-data (list (match-beginning 1) (match-end 1) | ||
| 3042 | (match-beginning 2) (match-end 2) | ||
| 3043 | (match-beginning 3) (match-end 3) | ||
| 3044 | (match-beginning 4) (match-end 4))) | ||
| 3045 | (setq done t | ||
| 3046 | retval t))) | ||
| 3047 | (setq done t))) | ||
| 3048 | retval))) | ||
| 3033 | 3049 | ||
| 3034 | (defun markdown--match-highlighting (last) | 3050 | (defun markdown--match-highlighting (last) |
| 3035 | (when markdown-enable-highlighting-syntax | 3051 | (when markdown-enable-highlighting-syntax |
| @@ -3543,30 +3559,25 @@ SEQ may be an atom or a sequence." | |||
| 3543 | (add-text-properties | 3559 | (add-text-properties |
| 3544 | (match-beginning 3) (match-end 3) rule-props))) | 3560 | (match-beginning 3) (match-end 3) rule-props))) |
| 3545 | ;; atx heading | 3561 | ;; atx heading |
| 3546 | (let ((header-end | 3562 | (let ((fontified-start |
| 3563 | (if (or markdown-hide-markup (not markdown-fontify-whole-heading-line)) | ||
| 3564 | (match-beginning 5) | ||
| 3565 | (match-beginning 0))) | ||
| 3566 | (fontified-end | ||
| 3547 | (if markdown-fontify-whole-heading-line | 3567 | (if markdown-fontify-whole-heading-line |
| 3548 | (min (point-max) (1+ (match-end 0))) | 3568 | (min (point-max) (1+ (match-end 0))) |
| 3549 | (match-end 0)))) | 3569 | (match-end 5)))) |
| 3550 | (add-text-properties | 3570 | (add-text-properties |
| 3551 | (match-beginning 4) (match-end 4) left-markup-props) | 3571 | (match-beginning 4) (match-end 4) left-markup-props) |
| 3552 | 3572 | ||
| 3553 | ;; If closing tag is present | 3573 | ;; If closing tag is present |
| 3554 | (if (match-end 6) | 3574 | (if (match-end 6) |
| 3555 | (progn | 3575 | (progn |
| 3556 | (if markdown-hide-markup | 3576 | (add-text-properties fontified-start fontified-end heading-props) |
| 3557 | (progn | 3577 | (when (or markdown-hide-markup (not markdown-fontify-whole-heading-line)) |
| 3558 | (add-text-properties | 3578 | (add-text-properties (match-beginning 6) (match-end 6) right-markup-props))) |
| 3559 | (match-beginning 5) header-end heading-props) | ||
| 3560 | (add-text-properties | ||
| 3561 | (match-beginning 6) (match-end 6) right-markup-props)) | ||
| 3562 | (add-text-properties | ||
| 3563 | (match-beginning 5) (match-end 5) heading-props) | ||
| 3564 | (add-text-properties | ||
| 3565 | (match-beginning 6) header-end right-markup-props))) | ||
| 3566 | ;; If closing tag is not present | 3579 | ;; If closing tag is not present |
| 3567 | (add-text-properties | 3580 | (add-text-properties fontified-start fontified-end heading-props))))) |
| 3568 | (match-beginning 5) header-end heading-props)) | ||
| 3569 | ))) | ||
| 3570 | t)) | 3581 | t)) |
| 3571 | 3582 | ||
| 3572 | (defun markdown-fontify-tables (last) | 3583 | (defun markdown-fontify-tables (last) |
| @@ -3812,12 +3823,12 @@ prefixed with an integer from 1 to the length of | |||
| 3812 | (when (and beg skip-space) | 3823 | (when (and beg skip-space) |
| 3813 | (save-excursion | 3824 | (save-excursion |
| 3814 | (goto-char beg) | 3825 | (goto-char beg) |
| 3815 | (skip-chars-forward "[ \t]") | 3826 | (skip-chars-forward " \t") |
| 3816 | (setq beg (point)))) | 3827 | (setq beg (point)))) |
| 3817 | (when (and end skip-space) | 3828 | (when (and end skip-space) |
| 3818 | (save-excursion | 3829 | (save-excursion |
| 3819 | (goto-char end) | 3830 | (goto-char end) |
| 3820 | (skip-chars-backward "[ \t]") | 3831 | (skip-chars-backward " \t") |
| 3821 | (setq end (point)))) | 3832 | (setq end (point)))) |
| 3822 | (markdown-wrap-or-insert start-delim end-delim nil beg end)) | 3833 | (markdown-wrap-or-insert start-delim end-delim nil beg end)) |
| 3823 | (if (markdown--face-p (point) (list face)) | 3834 | (if (markdown--face-p (point) (list face)) |
| @@ -4894,7 +4905,7 @@ footnote text is found, NIL is returned." | |||
| 4894 | (save-excursion | 4905 | (save-excursion |
| 4895 | (goto-char (point-min)) | 4906 | (goto-char (point-min)) |
| 4896 | (when (re-search-forward (concat "^ \\{0,3\\}\\[" id "\\]:") nil t) | 4907 | (when (re-search-forward (concat "^ \\{0,3\\}\\[" id "\\]:") nil t) |
| 4897 | (skip-chars-forward "[ \t]") | 4908 | (skip-chars-forward " \t") |
| 4898 | (point)))) | 4909 | (point)))) |
| 4899 | 4910 | ||
| 4900 | (defun markdown-footnote-marker-positions () | 4911 | (defun markdown-footnote-marker-positions () |
| @@ -7692,12 +7703,14 @@ Return the name of the output buffer used." | |||
| 7692 | Insert the output in the buffer named OUTPUT-BUFFER-NAME." | 7703 | Insert the output in the buffer named OUTPUT-BUFFER-NAME." |
| 7693 | (interactive) | 7704 | (interactive) |
| 7694 | (setq output-buffer-name (markdown output-buffer-name)) | 7705 | (setq output-buffer-name (markdown output-buffer-name)) |
| 7695 | (with-current-buffer output-buffer-name | 7706 | (let ((css-path markdown-css-paths)) |
| 7696 | (set-buffer output-buffer-name) | 7707 | (with-current-buffer output-buffer-name |
| 7697 | (unless (markdown-output-standalone-p) | 7708 | (set-buffer output-buffer-name) |
| 7698 | (markdown-add-xhtml-header-and-footer output-buffer-name)) | 7709 | (setq-local markdown-css-paths css-path) |
| 7699 | (goto-char (point-min)) | 7710 | (unless (markdown-output-standalone-p) |
| 7700 | (html-mode)) | 7711 | (markdown-add-xhtml-header-and-footer output-buffer-name)) |
| 7712 | (goto-char (point-min)) | ||
| 7713 | (html-mode))) | ||
| 7701 | output-buffer-name) | 7714 | output-buffer-name) |
| 7702 | 7715 | ||
| 7703 | (defun markdown-other-window (&optional output-buffer-name) | 7716 | (defun markdown-other-window (&optional output-buffer-name) |
| @@ -9139,7 +9152,7 @@ position." | |||
| 9139 | (remove-text-properties start end '(face nil)) | 9152 | (remove-text-properties start end '(face nil)) |
| 9140 | (with-current-buffer | 9153 | (with-current-buffer |
| 9141 | (get-buffer-create | 9154 | (get-buffer-create |
| 9142 | (concat " markdown-code-fontification:" (symbol-name lang-mode))) | 9155 | (format " *markdown-code-fontification:%s*" (symbol-name lang-mode))) |
| 9143 | ;; Make sure that modification hooks are not inhibited in | 9156 | ;; Make sure that modification hooks are not inhibited in |
| 9144 | ;; the org-src-fontification buffer in case we're called | 9157 | ;; the org-src-fontification buffer in case we're called |
| 9145 | ;; from `jit-lock-function' (Bug#25132). | 9158 | ;; from `jit-lock-function' (Bug#25132). |
| @@ -10292,6 +10305,11 @@ rows and columns and the column alignment." | |||
| 10292 | (setq markdown-link-space-sub-char "-") | 10305 | (setq markdown-link-space-sub-char "-") |
| 10293 | (setq markdown-wiki-link-search-subdirectories t) | 10306 | (setq markdown-wiki-link-search-subdirectories t) |
| 10294 | (setq-local markdown-table-at-point-p-function #'gfm--table-at-point-p) | 10307 | (setq-local markdown-table-at-point-p-function #'gfm--table-at-point-p) |
| 10308 | (setq-local paragraph-separate | ||
| 10309 | (concat paragraph-separate | ||
| 10310 | "\\|" | ||
| 10311 | ;; GFM alert syntax | ||
| 10312 | "^>\s-*\\[!\\(?:NOTE\\|TIP\\|IMPORTANT\\|WARNING\\|CAUTION\\)\\]")) | ||
| 10295 | (add-hook 'post-self-insert-hook #'gfm--electric-pair-fence-code-block 'append t) | 10313 | (add-hook 'post-self-insert-hook #'gfm--electric-pair-fence-code-block 'append t) |
| 10296 | (markdown-gfm-parse-buffer-for-languages)) | 10314 | (markdown-gfm-parse-buffer-for-languages)) |
| 10297 | 10315 | ||
