From bb7d0abc12e60aa52c84e36b9fd3200d7f861f8b Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Thu, 17 Aug 2023 11:41:36 +0200 Subject: Upgrade lua-mode.el markdown-mode and yaml-mode --- .emacs.d/lisp/lua-mode.el | 17 ++--- .emacs.d/lisp/markdown-mode.el | 160 +++++++++++++++++++++++++++++++---------- .emacs.d/lisp/yaml-mode.el | 8 +-- 3 files changed, 134 insertions(+), 51 deletions(-) (limited to '.emacs.d/lisp') diff --git a/.emacs.d/lisp/lua-mode.el b/.emacs.d/lisp/lua-mode.el index 4c543f5..6ab4d43 100644 --- a/.emacs.d/lisp/lua-mode.el +++ b/.emacs.d/lisp/lua-mode.el @@ -396,10 +396,7 @@ If the latter is nil, the keymap translates into `lua-mode-map' verbatim.") "Buffer-local flag saying if this is a Lua REPL buffer.") (make-variable-buffer-local 'lua--repl-buffer-p) - -(defadvice compilation-find-file (around lua--repl-find-file - (marker filename directory &rest formats) - activate) +(defun lua--compilation-find-file (fn marker filename directory &rest formats) "Return Lua REPL buffer when looking for \"stdin\" file in it." (if (and lua--repl-buffer-p @@ -409,13 +406,12 @@ If the latter is nil, the keymap translates into `lua-mode-map' verbatim.") (not (file-exists-p (expand-file-name filename (when directory (expand-file-name directory)))))) - (setq ad-return-value (current-buffer)) - ad-do-it)) + (current-buffer) + (apply fn marker filename directory formats))) +(advice-add 'compilation-find-file :around #'lua--compilation-find-file) -(defadvice compilation-goto-locus (around lua--repl-goto-locus - (msg mk end-mk) - activate) +(defun lua--compilation-goto-locus (fn msg mk end-mk) "When message points to Lua REPL buffer, go to the message itself. Usually, stdin:XX line number points to nowhere." (let ((errmsg-buf (marker-buffer msg)) @@ -425,8 +421,9 @@ Usually, stdin:XX line number points to nowhere." (progn (compilation-set-window (display-buffer (marker-buffer msg)) msg) (goto-char msg)) - ad-do-it))) + (funcall fn msg mk end-mk)))) +(advice-add 'compilation-goto-locus :around #'lua--compilation-goto-locus) (defcustom lua-indent-string-contents nil "If non-nil, contents of multiline string will be indented. diff --git a/.emacs.d/lisp/markdown-mode.el b/.emacs.d/lisp/markdown-mode.el index 63a86ad..4bb1a57 100644 --- a/.emacs.d/lisp/markdown-mode.el +++ b/.emacs.d/lisp/markdown-mode.el @@ -7,7 +7,7 @@ ;; Maintainer: Jason R. Blevins ;; Created: May 24, 2007 ;; Version: 2.6-alpha -;; Package-Requires: ((emacs "26.1")) +;; Package-Requires: ((emacs "27.1")) ;; Keywords: Markdown, GitHub Flavored Markdown, itex ;; URL: https://jblevins.org/projects/markdown-mode/ @@ -704,7 +704,7 @@ Group 7 matches the title (optional). Group 8 matches the closing parenthesis.") (defconst markdown-regex-link-reference - "\\(?1:!\\)?\\(?2:\\[\\)\\(?3:[^]^][^]]*\\|\\)\\(?4:\\]\\)[ ]?\\(?5:\\[\\)\\(?6:[^]]*?\\)\\(?7:\\]\\)" + "\\(?1:!\\)?\\(?2:\\[\\)\\(?3:[^]^][^]]*\\|\\)\\(?4:\\]\\)\\(?5:\\[\\)\\(?6:[^]]*?\\)\\(?7:\\]\\)" "Regular expression for a reference link [text][id]. Group 1 matches the leading exclamation point (optional). Group 2 matches the opening square bracket for the link text. @@ -732,7 +732,7 @@ Group 2 matches only the label, without the surrounding markup. Group 3 matches the closing square bracket.") (defconst markdown-regex-header - "^\\(?:\\(?1:[^\r\n\t -].*\\)\n\\(?:\\(?2:=+\\)\\|\\(?3:-+\\)\\)\\|\\(?4:#+[ \t]+\\)\\(?5:.*?\\)\\(?6:[ \t]*#*\\)\\)$" + "^\\(?:\\(?1:[^\r\n\t -].*\\)\n\\(?:\\(?2:=+\\)\\|\\(?3:-+\\)\\)\\|\\(?4:#+[ \t]+\\)\\(?5:.*?\\)\\(?6:[ \t]+#+\\)?\\)$" "Regexp identifying Markdown headings. Group 1 matches the text of a setext heading. Group 2 matches the underline of a level-1 setext heading. @@ -861,6 +861,10 @@ Group 3 matches the text.") "[^ \n\t][ \t]*\\( \\)\n" "Regular expression for matching line breaks.") +(defconst markdown-regex-escape + "\\(\\\\\\)." + "Regular expression for matching escape sequences.") + (defconst markdown-regex-wiki-link "\\(?:^\\|[^\\]\\)\\(?1:\\(?2:\\[\\[\\)\\(?3:[^]|]+\\)\\(?:\\(?4:|\\)\\(?5:[^]]+\\)\\)?\\(?6:\\]\\]\\)\\)" "Regular expression for matching wiki links. @@ -1101,6 +1105,29 @@ Group 4 matches the text inside the delimiters.") 'markdown-metadata-markup nil) "Property list of all Markdown syntactic properties.") +(defvar markdown-literal-faces + '(markdown-inline-code-face + markdown-pre-face + markdown-math-face + markdown-url-face + markdown-plain-url-face + markdown-language-keyword-face + markdown-language-info-face + markdown-metadata-key-face + markdown-metadata-value-face + markdown-html-entity-face + markdown-html-tag-name-face + markdown-html-tag-delimiter-face + markdown-html-attr-name-face + markdown-html-attr-value-face + markdown-reference-face + markdown-footnote-marker-face + markdown-line-break-face + markdown-comment-face) + "A list of markdown-mode faces that contain literal text. +Literal text treats backslashes literally, rather than as an +escape character (see `markdown-match-escape').") + (defsubst markdown-in-comment-p (&optional pos) "Return non-nil if POS is in a comment. If POS is not given, use point instead." @@ -2216,6 +2243,7 @@ Depending on your font, some reasonable choices are: (4 'markdown-highlighting-face) (5 markdown-markup-properties))) (,markdown-regex-line-break . (1 'markdown-line-break-face prepend)) + (markdown-match-escape . ((1 markdown-markup-properties prepend))) (markdown-fontify-sub-superscripts) (markdown-match-inline-attributes . ((0 markdown-markup-properties prepend))) (markdown-match-leanpub-sections . ((0 markdown-markup-properties))) @@ -2947,6 +2975,18 @@ When FACELESS is non-nil, do not return matches where faces have been applied." (when markdown-enable-highlighting-syntax (re-search-forward markdown-regex-highlighting last t))) +(defun markdown-match-escape (last) + "Match escape characters (backslashes) from point to LAST. +Backlashes only count as escape characters outside of literal +regions (e.g. code blocks). See `markdown-literal-faces'." + (catch 'found + (while (search-forward-regexp markdown-regex-escape last t) + (let* ((face (get-text-property (match-beginning 1) 'face)) + (face-list (if (listp face) face (list face)))) + ;; Ignore any backslashes with a literal face. + (unless (cl-intersection face-list markdown-literal-faces) + (throw 'found t)))))) + (defun markdown-match-math-generic (regex last) "Match REGEX from point to LAST. REGEX is either `markdown-regex-math-inline-single' for matching @@ -3443,17 +3483,30 @@ SEQ may be an atom or a sequence." (add-text-properties (match-beginning 3) (match-end 3) rule-props))) ;; atx heading - (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)) + (let ((header-end + (if markdown-fontify-whole-heading-line + (min (point-max) (1+ (match-end 0))) + (match-end 0)))) (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 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))) + ;; If closing tag is not present (add-text-properties - (match-beginning 6) (match-end 6) right-markup-props))))) + (match-beginning 5) header-end heading-props)) + ))) t)) (defun markdown-fontify-tables (last) @@ -3504,17 +3557,30 @@ SEQ may be an atom or a sequence." `(display ,display-string)))))))) t)) +(defun markdown--fontify-hrs-view-mode (hr-char) + (if (and hr-char (display-supports-face-attributes-p '(:extend t))) + (add-text-properties + (match-beginning 0) (match-end 0) + `(face + (:inherit markdown-hr-face :underline t :extend t) + font-lock-multiline t + display "\n")) + (let ((hr-len (and hr-char (/ (1- (window-body-width)) (char-width hr-char))))) + (add-text-properties + (match-beginning 0) (match-end 0) + `(face + markdown-hr-face font-lock-multiline t + display ,(make-string hr-len hr-char)))))) + (defun markdown-fontify-hrs (last) "Add text properties to horizontal rules from point to LAST." (when (markdown-match-hr last) (let ((hr-char (markdown--first-displayable markdown-hr-display-char))) - (add-text-properties - (match-beginning 0) (match-end 0) - `(face markdown-hr-face - font-lock-multiline t - ,@(when (and markdown-hide-markup hr-char) - `(display ,(make-string - (1- (window-body-width)) hr-char))))) + (if (and markdown-hide-markup hr-char) + (markdown--fontify-hrs-view-mode hr-char) + (add-text-properties + (match-beginning 0) (match-end 0) + `(face markdown-hr-face font-lock-multiline t))) t))) (defun markdown-fontify-sub-superscripts (last) @@ -4539,7 +4605,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 details here https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details." (interactive) (let ((details-open-tag "
") (details-close-tag "
") @@ -4599,6 +4665,7 @@ element. More detais here https://developer.mozilla.org/en-US/docs/Web/HTML/Elem (interactive) (let ((fn (markdown-footnote-counter-inc))) (insert (format "[^%d]" fn)) + (push-mark (point) t) (markdown-footnote-text-find-new-location) (markdown-ensure-blank-line-before) (unless (markdown-cur-line-blank-p) @@ -5000,9 +5067,10 @@ list simply adds a blank line)." (setq bounds (markdown-cur-list-item-bounds))) (let ((beg (cl-first bounds)) (end (cl-second bounds)) - (length (cl-fourth bounds))) + (nonlist-indent (cl-fourth bounds)) + (checkbox (cl-sixth bounds))) ;; Point is in a list item - (if (= (- end beg) length) + (if (= (- end beg) (+ nonlist-indent (length checkbox))) ;; Delete blank list (progn (delete-region beg end) @@ -5716,7 +5784,7 @@ See also `markdown-mode-map'.") (defun markdown-imenu-create-nested-index () "Create and return a nested imenu index alist for the current buffer. See `imenu-create-index-function' and `imenu--index-alist' for details." - (let* ((root '(nil . nil)) + (let* ((root (list nil)) (min-level 9999) hashes headers) (save-excursion @@ -7427,6 +7495,12 @@ Standalone XHTML output is identified by an occurrence of stylesheet-path) "\" />")) +(defun markdown-escape-title (title) + "Escape a minimum set of characters in TITLE so they don't clash with html." + (replace-regexp-in-string ">" ">" + (replace-regexp-in-string "<" "<" + (replace-regexp-in-string "&" "&" title)))) + (defun markdown-add-xhtml-header-and-footer (title) "Wrap XHTML header and footer with given TITLE around current buffer." (goto-char (point-min)) @@ -7435,7 +7509,7 @@ Standalone XHTML output is identified by an occurrence of "\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n\n" "\n\n" "\n") - (insert title) + (insert (markdown-escape-title title)) (insert "\n") (unless (= (length markdown-content-type) 0) (insert @@ -7774,19 +7848,19 @@ Value is a list of elements describing the link: ((thing-at-point-looking-at markdown-regex-link-inline) (setq bang (match-string-no-properties 1) begin (match-beginning 0) - end (match-end 0) text (match-string-no-properties 3) url (match-string-no-properties 6)) - (if (match-end 7) - (setq title (substring (match-string-no-properties 7) 1 -1)) - ;; #408 URL contains close parenthesis case - (goto-char (match-beginning 5)) - (let ((paren-end (scan-sexps (point) 1))) - (when (and paren-end (< end paren-end)) - (setq url (buffer-substring (match-beginning 6) (1- paren-end))))))) + ;; consider nested parentheses + ;; if link target contains parentheses, (match-end 0) isn't correct end position of the link + (let* ((close-pos (scan-sexps (match-beginning 5) 1)) + (destination-part (string-trim (buffer-substring-no-properties (1+ (match-beginning 5)) (1- close-pos))))) + (setq end close-pos) + (if (string-match "\\([^ ]+\\)\\s-+\\(.+\\)" destination-part) + (setq url (match-string-no-properties 1 destination-part) + title (substring (match-string-no-properties 2 destination-part) 1 -1)) + (setq url destination-part)))) ;; Reference link at point. - ((or (thing-at-point-looking-at markdown-regex-link-inline) - (thing-at-point-looking-at markdown-regex-link-reference)) + ((thing-at-point-looking-at markdown-regex-link-reference) (setq bang (match-string-no-properties 1) begin (match-beginning 0) end (match-end 0) @@ -8755,7 +8829,7 @@ mode to use is `tuareg-mode'." "Return major mode that should be used for LANG. LANG is a string, and the returned major mode is a symbol." (cl-find-if - 'fboundp + #'markdown--lang-mode-predicate (nconc (list (cdr (assoc lang markdown-code-lang-modes)) (cdr (assoc (downcase lang) markdown-code-lang-modes))) (and (fboundp 'treesit-language-available-p) @@ -8767,6 +8841,20 @@ LANG is a string, and the returned major mode is a symbol." (intern (concat lang "-mode")) (intern (concat (downcase lang) "-mode")))))) +(defun markdown--lang-mode-predicate (mode) + (and mode + (fboundp mode) + (or + ;; 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) + for func = (cdr pair) + thereis (and (atom func) (eq mode func))) + ;; https://github.com/jrblevin/markdown-mode/issues/761 + (cl-loop for pair in auto-mode-alist + for func = (cdr pair) + thereis (and (atom func) (eq mode func)))))) + (defun markdown-fontify-code-blocks-generic (matcher last) "Add text properties to next code block from point to LAST. Use matching function MATCHER." @@ -9667,8 +9755,8 @@ spaces, or alternatively a TAB should be used as the separator." Optional arguments ROWS, COLUMNS, and ALIGN specify number of rows and columns and the column alignment." (interactive) - (let* ((rows (or rows (string-to-number (read-string "Row size: ")))) - (columns (or columns (string-to-number (read-string "Column size: ")))) + (let* ((rows (or rows (read-number "Number of Rows: "))) + (columns (or columns (read-number "Number of Columns: "))) (align (or align (read-string "Alignment ([l]eft, [r]ight, [c]enter, or RET for default): "))) (align (cond ((equal align "l") ":--") ((equal align "r") "--:") diff --git a/.emacs.d/lisp/yaml-mode.el b/.emacs.d/lisp/yaml-mode.el index fc46e05..d3c1da8 100644 --- a/.emacs.d/lisp/yaml-mode.el +++ b/.emacs.d/lisp/yaml-mode.el @@ -123,7 +123,7 @@ that key is pressed to begin a block literal." "Regexp matching a line containing only (valid) whitespace.") (defconst yaml-directive-re "^\\(?:--- \\)? *%\\(\\w+\\)" - "Regexp matching a line contatining a YAML directive.") + "Regexp matching a line containing a YAML directive.") (defconst yaml-document-delimiter-re "^\\(?:---\\|[.][.][.]\\)" "Rexexp matching a YAML document delimiter line.") @@ -368,11 +368,9 @@ back-dent the line by `yaml-indent-offset' spaces. On reaching column (let ((ci (current-indentation)) (need (yaml-compute-indentation))) (save-excursion - (beginning-of-line) - (delete-horizontal-space) (if (and (equal last-command this-command) (/= ci 0)) - (indent-to (* (/ (- ci 1) yaml-indent-offset) yaml-indent-offset)) - (indent-to need))) + (indent-line-to (* (/ (- ci 1) yaml-indent-offset) yaml-indent-offset)) + (indent-line-to need))) (if (< (current-column) (current-indentation)) (forward-to-indentation 0)))) -- cgit v1.3