From 784e509bded0fe41dd9908022a92c54ac8c21a2c Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Thu, 29 Dec 2022 00:58:50 -0800 Subject: [PATCH 01/15] Fix c-ts-mode bracket indentation (bug#60398) * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Use new anchor. (c-ts-mode--bracket-children-anchor): New anchor function. --- lisp/progmodes/c-ts-mode.el | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 8ba6cdee42d..82458ba5adb 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -118,7 +118,7 @@ MODE is either `c' or `cpp'." `(((parent-is "translation_unit") parent-bol 0) ((node-is ")") parent 1) ((node-is "]") parent-bol 0) - ((node-is "}") (and parent parent-bol) 0) + ((node-is "}") c-ts-mode--bracket-children-anchor 0) ((node-is "else") parent-bol 0) ((node-is "case") parent-bol 0) ((node-is "preproc_arg") no-indent) @@ -133,7 +133,8 @@ MODE is either `c' or `cpp'." ((match "#endif" "preproc_if") point-min 0) ((match "preproc_function_def" "compound_statement") point-min 0) ((match "preproc_call" "compound_statement") point-min 0) - ((parent-is "compound_statement") (and parent parent-bol) c-ts-mode-indent-offset) + ((parent-is "compound_statement") + c-ts-mode--bracket-children-anchor c-ts-mode-indent-offset) ((parent-is "function_definition") parent-bol 0) ((parent-is "conditional_expression") first-sibling 0) ((parent-is "assignment_expression") parent-bol c-ts-mode-indent-offset) @@ -189,6 +190,21 @@ MODE is either `c' or `cpp'." ('linux (alist-get 'linux (c-ts-mode--indent-styles mode))))))) `((,mode ,@style)))) +(defun c-ts-mode--bracket-children-anchor (_n parent &rest _) + "This anchor is used for children of a compound_statement. +So anything inside a {} block. PARENT should be the +compound_statement. This anchor looks at the {, if itson its own +line, anchor at it, if it has stuff before it, anchor at the +beginning of grandparent." + (save-excursion + (goto-char (treesit-node-start parent)) + (let ((bol (line-beginning-position))) + (skip-chars-backward " \t") + (treesit-node-start + (if (< bol (point)) + (treesit-node-parent parent) + parent))))) + (defun c-ts-mode--looking-at-star (&rest _) "A tree-sitter simple indent matcher. Matches if there is a \"*\" after point (ignoring whitespace in From 9d814bea4600ac28dcdbf9caf386467551d7d9be Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 18 Dec 2022 00:24:16 -0500 Subject: [PATCH 02/15] ; whitespace.el: Use the new 'ert-with-buffer-selected' in tests Commit 286c48137f69fa96b80d197da90c69a42df604a3 added a new `ert-with-test-buffer-selected' macro. Use that macro in 'whitespace-mode' tests to avoid code duplication. (Bug#60332) * test/lisp/whitespace-tests.el (whitespace--with-buffer-selected): Macro deleted. (whitespace-tests--indirect-clone-breaks-base-markers) (whitespace-tests--indirect-clone-markers) (whitespace-tests--regular-clone-markers): Use 'ert-with-buffer-selected'. --- test/lisp/whitespace-tests.el | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/test/lisp/whitespace-tests.el b/test/lisp/whitespace-tests.el index 12f6cb99a23..d72748cd0c9 100644 --- a/test/lisp/whitespace-tests.el +++ b/test/lisp/whitespace-tests.el @@ -42,13 +42,6 @@ nil, `whitespace-mode' is left disabled." '(whitespace-mode 1)) ,@body))) -(defmacro whitespace--with-buffer-selected (buffer-or-name &rest body) - (declare (debug (form body)) (indent 1)) - `(save-window-excursion - (with-current-buffer (or ,buffer-or-name (current-buffer)) - (with-selected-window (display-buffer (current-buffer)) - ,@body)))) - (defun whitespace-tests--faceup (&rest lines) "Convenience wrapper around `faceup-test-font-lock-buffer'. Returns non-nil if the concatenated LINES match the current @@ -354,7 +347,7 @@ buffer's content." (indirect (clone-indirect-buffer (buffer-name) nil))) (should (eq (marker-buffer whitespace-bob-marker) base)) (should (eq (marker-buffer whitespace-eob-marker) base)) - (whitespace--with-buffer-selected indirect + (ert-with-buffer-selected indirect ;; Mutate the indirect buffer to update its bob/eob markers. (execute-kbd-macro (kbd "z RET M-< a"))) ;; With Bug#59618, the above mutation would cause the base @@ -382,7 +375,7 @@ buffer's content." ;; because the buffer should only be killed on success. (indirect (clone-indirect-buffer nil nil))) (whitespace-tests--check-markers base 2 4) - (whitespace--with-buffer-selected indirect + (ert-with-buffer-selected indirect (whitespace-tests--check-markers indirect 2 4) ;; Mutate the buffer to trigger `after-change-functions' and ;; thus `whitespace--update-bob-eob'. @@ -405,7 +398,7 @@ buffer's content." ;; the buffer should only be killed on success. (clone (clone-buffer))) (whitespace-tests--check-markers orig 2 4) - (whitespace--with-buffer-selected clone + (ert-with-buffer-selected clone (whitespace-tests--check-markers clone 2 4) (execute-kbd-macro (kbd "z RET M-< a")) (whitespace-tests--check-markers clone 1 8)) From 38c35bf0f6a938001dfecbe439addf8fb62897c6 Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Thu, 29 Dec 2022 01:28:25 -0800 Subject: [PATCH 03/15] Clean up treesit-default-defun-skipper and add comments * lisp/treesit.el (treesit-default-defun-skipper): Clean up, fix some small issue, add comment. --- lisp/treesit.el | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lisp/treesit.el b/lisp/treesit.el index 4ee0fba79b7..0ba4395a6b4 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -1744,13 +1744,17 @@ this function depends on `treesit-defun-type-regexp' and This function tries to move to the beginning of a line, either by moving to the empty newline after a defun, or to the beginning of the current line if the beginning of the defun is indented." - (cond ((and (looking-at (rx (* (or " " "\\t")) "\n")) - (not (looking-at (rx bol)))) - (goto-char (match-end 0))) - ((save-excursion - (skip-chars-backward " \t") - (eq (point) (line-beginning-position))) - (goto-char (line-beginning-position))))) + ;; Moving forward, point at the end of a line and not already on an + ;; empty line: go to BOL of the next line (which hopefully is an + ;; empty line). + (cond ((and (looking-at (rx (* (or " " "\t")) "\n")) + (not (bolp))) + (forward-line 1)) + ;; Moving backward, but there are some whitespace (and only + ;; whitespace) between point and BOL: go back to BOL. + ((looking-back (rx (+ (or " " "\t"))) + (line-beginning-position)) + (beginning-of-line)))) ;; prev-sibling: ;; 1. end-of-node before pos From 706ed85285515e7047e16608815c1d02d4907b07 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 29 Dec 2022 13:52:09 +0200 Subject: [PATCH 04/15] Avoid assertion violations in treesit.c with --enable-checking * src/treesit.c (Ftreesit_node_first_child_for_pos) (Ftreesit_node_descendant_for_range): Check validity of buffer positions before converting them to byte-positions, to avoid assertion violations in buf_charpos_to_bytepos. --- src/treesit.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/treesit.c b/src/treesit.c index 6570ada1d92..eaa563a54c4 100644 --- a/src/treesit.c +++ b/src/treesit.c @@ -2070,12 +2070,11 @@ Note that this function returns an immediate child, not the smallest struct buffer *buf = XBUFFER (XTS_PARSER (XTS_NODE (node)->parser)->buffer); ptrdiff_t visible_beg = XTS_PARSER (XTS_NODE (node)->parser)->visible_beg; - ptrdiff_t byte_pos = buf_charpos_to_bytepos (buf, XFIXNUM (pos)); treesit_check_position (pos, buf); - treesit_initialize (); + ptrdiff_t byte_pos = buf_charpos_to_bytepos (buf, XFIXNUM (pos)); TSNode treesit_node = XTS_NODE (node)->node; TSNode child; if (NILP (named)) @@ -2106,14 +2105,14 @@ If NODE is nil, return nil. */) struct buffer *buf = XBUFFER (XTS_PARSER (XTS_NODE (node)->parser)->buffer); ptrdiff_t visible_beg = XTS_PARSER (XTS_NODE (node)->parser)->visible_beg; - ptrdiff_t byte_beg = buf_charpos_to_bytepos (buf, XFIXNUM (beg)); - ptrdiff_t byte_end = buf_charpos_to_bytepos (buf, XFIXNUM (end)); treesit_check_position (beg, buf); treesit_check_position (end, buf); treesit_initialize (); + ptrdiff_t byte_beg = buf_charpos_to_bytepos (buf, XFIXNUM (beg)); + ptrdiff_t byte_end = buf_charpos_to_bytepos (buf, XFIXNUM (end)); TSNode treesit_node = XTS_NODE (node)->node; TSNode child; if (NILP (named)) From 60418e6f09c67924e3e05eb4948e109d8f7c4073 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Thu, 29 Dec 2022 19:41:41 +0200 Subject: [PATCH 05/15] * src/keyboard.c (echo_add_key): Use recently rebound C-h key C-q (bug#60249) --- src/keyboard.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/keyboard.c b/src/keyboard.c index d68b50428a9..7bf89ac7d4b 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -503,11 +503,10 @@ echo_add_key (Lisp_Object c) if ((NILP (echo_string) || SCHARS (echo_string) == 0) && help_char_p (c)) { - AUTO_STRING (str, " (Type ? for further options, q for quick help)"); + AUTO_STRING (str, " (Type ? for further options, C-q for quick help)"); AUTO_LIST2 (props, Qface, Qhelp_key_binding); Fadd_text_properties (make_fixnum (7), make_fixnum (8), props, str); - Fadd_text_properties (make_fixnum (30), make_fixnum (31), props, -str); + Fadd_text_properties (make_fixnum (30), make_fixnum (33), props, str); new_string = concat2 (new_string, str); } From 0aea1cf8190aa804a0d11a67b4a3cb4b715ae82d Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Thu, 29 Dec 2022 19:45:12 +0200 Subject: [PATCH 06/15] * lisp/hi-lock.el (hi-lock--regexps-at-point): Fix bug (bug#60241). Handle two cases: when a pattern is a regexp or a function. --- lisp/hi-lock.el | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el index a45e74eca26..bc631747e6d 100644 --- a/lisp/hi-lock.el +++ b/lisp/hi-lock.el @@ -569,24 +569,29 @@ the major mode specifies support for Font Lock." (when (and face-before face-after (not (eq face-before face-after))) (setq face-before nil)) (when (or face-after face-before) - (let* ((hi-text - (buffer-substring-no-properties - (if face-before - (or (previous-single-property-change (point) 'face) - (point-min)) - (point)) - (if face-after - (or (next-single-property-change (point) 'face) - (point-max)) - (point))))) + (let* ((beg (if face-before + (or (previous-single-property-change (point) 'face) + (point-min)) + (point))) + (end (if face-after + (or (next-single-property-change (point) 'face) + (point-max)) + (point)))) ;; Compute hi-lock patterns that match the ;; highlighted text at point. Use this later in ;; during completing-read. (dolist (hi-lock-pattern hi-lock-interactive-patterns) - (let ((regexp (or (car (rassq hi-lock-pattern hi-lock-interactive-lighters)) - (car hi-lock-pattern)))) - (if (string-match regexp hi-text) - (push regexp regexps))))))) + (let ((pattern (or (rassq hi-lock-pattern hi-lock-interactive-lighters) + (car hi-lock-pattern)))) + (cond + ((stringp pattern) + (when (string-match pattern (buffer-substring-no-properties beg end)) + (push pattern regexps))) + ((functionp (cadr pattern)) + (save-excursion + (goto-char beg) + (when (funcall (cadr pattern) end) + (push (car pattern) regexps)))))))))) regexps)) (defvar-local hi-lock--unused-faces nil From 793641a3db5e14cd2eeb251d2f473b1035192560 Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Thu, 29 Dec 2022 11:34:28 -0800 Subject: [PATCH 07/15] ; * lisp/progmodes/js.el: Fix byte-compile warning. --- lisp/progmodes/js.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index 4dece11d1c1..0cc673a80ff 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -74,6 +74,8 @@ (declare-function treesit-node-start "treesit.c") (declare-function treesit-node-end "treesit.c") (declare-function treesit-node-type "treesit.c") +(declare-function treesit-query-compile "treesit.c") +(declare-function treesit-query-capture "treesit.c") ;;; Constants @@ -3642,8 +3644,9 @@ OVERRIDE is the override flag described in "call_expression"))) (defvar js--treesit-lhs-identifier-query - (treesit-query-compile 'javascript '((identifier) @id - (property_identifier) @id)) + (when (treesit-available-p) + (treesit-query-compile 'javascript '((identifier) @id + (property_identifier) @id))) "Query that captures identifier and query_identifier.") (defun js--treesit-fontify-assignment-lhs (node override start end &rest _) From a96a7c811517063053a1dffc30ac94deffad503f Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Thu, 29 Dec 2022 11:41:26 -0800 Subject: [PATCH 08/15] ; * lisp/textmodes/css-mode.el (css-ts-mode): Fix imenu setup. --- lisp/textmodes/css-mode.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el index 204331ec72f..19f5fa303f9 100644 --- a/lisp/textmodes/css-mode.el +++ b/lisp/textmodes/css-mode.el @@ -1821,8 +1821,8 @@ can also be used to fill comments. (property constant string) (error variable function operator bracket))) (setq-local treesit-simple-imenu-settings - `( nil ,(rx bos (or "rule_set" "media_statement") eos) - nil nil)) + `(( nil ,(rx bos (or "rule_set" "media_statement") eos) + nil nil))) (treesit-major-mode-setup))) ;;;###autoload From 558b59d81b938fc434e62523106360b9704c88e2 Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Thu, 29 Dec 2022 11:52:06 -0800 Subject: [PATCH 09/15] Add color fontification in css-ts-mode (bug#60405) * lisp/textmodes/css-mode.el (css-ts-mode): Add color fontification and syntax-propertize-function. --- lisp/textmodes/css-mode.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el index 19f5fa303f9..e8d97259489 100644 --- a/lisp/textmodes/css-mode.el +++ b/lisp/textmodes/css-mode.el @@ -1804,11 +1804,15 @@ can also be used to fill comments. :syntax-table css-mode-syntax-table (when (treesit-ready-p 'css) ;; Borrowed from `css-mode'. + (setq-local syntax-propertize-function + css-syntax-propertize-function) (add-hook 'completion-at-point-functions #'css-completion-at-point nil 'local) (setq-local fill-paragraph-function #'css-fill-paragraph) (setq-local adaptive-fill-function #'css-adaptive-fill) - (setq-local add-log-current-defun-function #'css-current-defun-name) + ;; `css--fontify-region' first calls the default function, which + ;; will call tree-sitter's function, then it fontifies colors. + (setq-local font-lock-fontify-region-function #'css--fontify-region) ;; Tree-sitter specific setup. (treesit-parser-create 'css) From 7ccb88486eb289a1a59dcb01ae604fc6c31ea804 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 29 Dec 2022 22:04:44 +0200 Subject: [PATCH 10/15] ; * etc/DEBUG: Update MS-Windows specifics for GDB 13 and later. --- etc/DEBUG | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/etc/DEBUG b/etc/DEBUG index ef9160a2090..ee134999dac 100644 --- a/etc/DEBUG +++ b/etc/DEBUG @@ -277,8 +277,13 @@ GDB: If you do this, then typing C-c or C-BREAK into the console window through which you interact with GDB will stop Emacs and return control to the debugger, no matter if Emacs displays GUI or text-mode frames. -This is the only reliable alternative on MS-Windows to get control to -the debugger, besides setting breakpoints in advance. +With GDB versions before 13.1, this is the only reliable alternative +on MS-Windows to get control to the debugger, besides setting +breakpoints in advance. GDB 13.1 changed the way C-c and C-BREAK are +handled on Windows, so with those newer versions, you don't need the +"set new-console 1" setting to be able to interrupt Emacs by typing +C-c or C-BREAK into the console window from which you started Emacs +and where you interact with GDB. ** Examining Lisp object values. From beed746f944aba2559192c057ea294233876e99d Mon Sep 17 00:00:00 2001 From: Gregory Heytings Date: Thu, 29 Dec 2022 21:50:26 +0000 Subject: [PATCH 11/15] Fix completion when completion-auto-select is set * lisp/minibuffer.el (completion--do-completion): Do not display "Complete, but not unique" messages when completion-auto-select is set. Fixes bug#60359. --- lisp/minibuffer.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 6e42296e7ba..7a720cf2c0a 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -1474,7 +1474,10 @@ when the buffer's text is already an exact match." (if (and (eq this-command last-command) completion-auto-help) (minibuffer-completion-help beg end)) (completion--done completion 'exact - (unless expect-exact + (unless (or expect-exact + (and completion-auto-select + (eq this-command last-command) + completion-auto-help)) "Complete, but not unique")))) (minibuffer--bitset completed t exact)))))))) From dafa6d6badd6552b6f88ba884e3e5dadb362380d Mon Sep 17 00:00:00 2001 From: Gregory Heytings Date: Mon, 19 Dec 2022 22:18:22 +0000 Subject: [PATCH 12/15] Handle non-string values in pcomplete * lisp/pcomplete.el (pcomplete-arg): When pcomplete-parse-arguments-function returns a non-string value, return the string the user typed in, and attach the value as a text property to that string. Fixes bug#59956 and bug#60021. --- lisp/pcomplete.el | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lisp/pcomplete.el b/lisp/pcomplete.el index 4e3a88bbda8..2d3730e294a 100644 --- a/lisp/pcomplete.el +++ b/lisp/pcomplete.el @@ -645,13 +645,26 @@ parts of the list. The OFFSET argument is added to/taken away from the index that will be used. This is really only useful with `first' and `last', for -accessing absolute argument positions." - (nth (+ (pcase index - ('first 0) - ('last pcomplete-last) - (_ (- pcomplete-index (or index 0)))) - (or offset 0)) - pcomplete-args)) +accessing absolute argument positions. + +When the argument has been transformed into something that is not +a string by `pcomplete-parse-arguments-function', the text +representation of the argument, namely what the user actually +typed in, is returned, and the value of the argument is stored in +the pcomplete-arg-value text property of that string." + (let ((arg + (nth (+ (pcase index + ('first 0) + ('last pcomplete-last) + (_ (- pcomplete-index (or index 0)))) + (or offset 0)) + pcomplete-args))) + (if (stringp arg) + arg + (propertize + (buffer-substring (pcomplete-begin index offset) + (pcomplete-begin (1- (or index 0)) offset)) + 'pcomplete-arg-value arg)))) (defun pcomplete-begin (&optional index offset) "Return the beginning position of the INDEXth argument. From d086cd6cf877c6ca7af6712f9b79b52dd0caa934 Mon Sep 17 00:00:00 2001 From: Gregory Heytings Date: Thu, 29 Dec 2022 22:41:58 +0000 Subject: [PATCH 13/15] Clarify the documentation of 'set-face-attribute' * lisp/faces.el (set-face-attribute): Mention the evaluation order of attribute-value pairs in the docstring. * doc/lispref/display.texi (Attribute Functions): Likewise, and explain with an example that a different argument order might give different results. Also align the documentation in the manual with that of the docstring, whose changes were discussed in bug#57499 but not included in the manual. --- doc/lispref/display.texi | 28 +++++++++++++++++----------- lisp/faces.el | 4 ++++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 37434994548..5397489e44f 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -3057,17 +3057,23 @@ If @var{frame} is @code{t}, this function sets the default attributes for newly created frames; they will effectively override the attribute values specified by @code{defface}. If @var{frame} is @code{nil}, this function sets the attributes for all existing frames, as well as -for newly created frames. However, if you want to @emph{reset} the -value of an attribute to @code{unspecified} in a way that also affects -newly created frames, you @emph{must} explicitly call this function -with @var{frame} set to @code{t} and the value of the attribute set to -@code{unspecified} (@emph{not} @code{nil}!@:), in addition to the call -with @var{frame} set to @code{nil}. This is because the default -attributes for newly created frames are merged with the face's spec in -@code{defface} when a new frame is created, and so having -@code{unspecified} in the default attributes for new frames will be -unable to override @code{defface}; the special call to this function -as described above will arrange for @code{defface} to be overridden. +for newly created frames. + +To @emph{unset} the value of an attribute, that is, to indicate that +the face doesn't by itself specify a value for the attribute, the +special value @code{unspecified} (@emph{not} @code{nil}!@:) must be +used. + +Note that the attribute-value pairs are evaluated in the order they +are specified, except the @code{:family} and @code{:foundry} +attributes, which are evaluated first. This means both that only the +last value of a given attribute will be used, and that in some cases a +different order will give different results. For example, when +@code{:weight} is placed before @code{:font}, the weight value is +applied to the current font of the face, and might be rounded to the +closest available weight of that font, whereas when @code{:font} is +placed before @code{:weight} the weight value is applied to the +specified font. @end defun The following commands and functions mostly provide compatibility diff --git a/lisp/faces.el b/lisp/faces.el index 29e26e4c651..fe683e437f5 100644 --- a/lisp/faces.el +++ b/lisp/faces.el @@ -690,6 +690,10 @@ be reset to `unspecified' when creating new frames, disregarding what the FACE's face spec says, call this function with FRAME set to t and the ATTRIBUTE's value set to `unspecified'. +Note that the ATTRIBUTE VALUE pairs are evaluated in the order +they are specified, except the `:family' and `:foundry' +attributes which are evaluated first. + The following attributes are recognized: `:family' From ab38abfdf75e091b9970dd3ba977aaa1b6067cc3 Mon Sep 17 00:00:00 2001 From: Roland Winkler Date: Thu, 29 Dec 2022 23:22:48 -0600 Subject: [PATCH 14/15] lisp/textmodes/bibtex.el: Treat $ as punctuation in BibTeX fields (bug#50202) --- lisp/textmodes/bibtex.el | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el index f4b557f443f..a1a3cbd8f14 100644 --- a/lisp/textmodes/bibtex.el +++ b/lisp/textmodes/bibtex.el @@ -1822,8 +1822,9 @@ Initialized by `bibtex-set-dialect'.") 1 '(11)))) (defvar bibtex-font-lock-keywords - ;; entry type and reference key - `((,bibtex-any-entry-maybe-empty-head + `(("\\$[^$\n]+\\$" . font-lock-string-face) ; bug#50202 + ;; entry type and reference key + (,bibtex-any-entry-maybe-empty-head (,bibtex-type-in-head font-lock-function-name-face) (,bibtex-key-in-head font-lock-constant-face nil t)) ;; optional field names (treated as comments) @@ -3631,8 +3632,11 @@ if that value is non-nil. (setq-local fill-paragraph-function #'bibtex-fill-field) (setq-local font-lock-defaults '(bibtex-font-lock-keywords - nil t ((?$ . "\"") - ;; Mathematical expressions should be fontified as strings + nil t ((?$ . ".") + ;; Mathematical expressions should be fontified + ;; as strings. Yet `$' may also appear in certain + ;; fields like `URL' when it does not delimit + ;; a math expression (bug#50202). (?\" . ".") ;; Quotes are field delimiters and quote-delimited ;; entries should be fontified in the same way as From 644c71d6788d268cb065bd9317efb8a16a8236e6 Mon Sep 17 00:00:00 2001 From: Roland Winkler Date: Thu, 29 Dec 2022 23:31:08 -0600 Subject: [PATCH 15/15] lisp/textmodes/bibtex.el: fix bibtex-beginning-of-entry (bug#56636) lisp/textmodes/bibtex.el (bibtex-beginning-of-entry): use bibtex-any-entry-maybe-empty-head (bug#56636) --- lisp/textmodes/bibtex.el | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el index a1a3cbd8f14..23909742889 100644 --- a/lisp/textmodes/bibtex.el +++ b/lisp/textmodes/bibtex.el @@ -4083,11 +4083,19 @@ INIT is surrounded by field delimiters, unless NODELIM is non-nil." If inside an entry, move to the beginning of it, otherwise move to the beginning of the previous entry. If point is ahead of all BibTeX entries move point to the beginning of buffer. Return the new location of point." + ;; This command is similar to `beginning-of-defun', but with historical + ;; differences. + ;; - It does not move point to the previous entry if point is already + ;; at the beginning of an entry + ;; - It does not take an optional ARG that moves backward to the beginning + ;; of a defun ARG times. + ;; - It returns point and the code relies on this. (interactive) - (skip-chars-forward " \t") - (if (looking-at "@") - (forward-char)) - (re-search-backward "^[ \t]*@" nil 'move) + (beginning-of-line) + ;; `bibtex-any-valid-entry-type' would fail if users "disable" + ;; an entry by chosing an invalid entry type. + (or (looking-at bibtex-any-entry-maybe-empty-head) + (re-search-backward bibtex-any-entry-maybe-empty-head nil 'move)) (point)) (defun bibtex-end-of-entry ()