From 20a95d6cc376c5927e616681e080affa8817ac9a Mon Sep 17 00:00:00 2001 From: Adam Beckmeyer Date: Fri, 15 Mar 2024 09:35:03 -0400 Subject: [PATCH 1/2] Strip whitespace in latexsub :exit-function According to the docstring for completion-extra-properties, the "STRING" passed to the :exit-function should be the bare text to which the field was completed, but helm-mode adds an extra space at the end of "STRING". Since none of our latexsubs include whitespace, we can safely strip whitespace in the :exit-function and work around this helm bug. I will file an upstring bug report against helm, but I think it's worth fixing quickly here since it's only a simple 3-line change. Closes #204. --- julia-mode-tests.el | 2 ++ julia-mode.el | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/julia-mode-tests.el b/julia-mode-tests.el index 1b4e990..f15b382 100644 --- a/julia-mode-tests.el +++ b/julia-mode-tests.el @@ -963,6 +963,8 @@ end" 'end-of-defun "n == 0" "return fact(x)[ \n]+end" 'end 2)) (should (equal (julia--call-latexsub-exit-function "\\kappa\\alpha(" 7 13 "\\alpha" t) "\\kappaα(")) + ;; Test that whitespace is stripped from `:exit-function' NAME for compatibility with helm + (should (equal (julia--call-latexsub-exit-function "x\\alpha " 2 8 "\\alpha " t) "xα ")) ;; test that LaTeX not expanded when `julia-automatic-latexsub' is nil (should (equal (julia--call-latexsub-exit-function "\\alpha" 1 7 "\\alpha" nil) "\\alpha")) (should (equal (julia--call-latexsub-exit-function "x\\alpha " 2 8 "\\alpha" nil) "x\\alpha ")) diff --git a/julia-mode.el b/julia-mode.el index 0260046..a702f1d 100644 --- a/julia-mode.el +++ b/julia-mode.el @@ -910,8 +910,12 @@ buffer where the LaTeX symbol starts." ;; ). Instead of automatic ;; expansion, user can either enable `abbrev-mode' or call `expand-abbrev'. (when-let (((eq status 'finished)) - (symb (abbrev-symbol name julia-latexsub-abbrev-table)) - (end (+ beg (length name)))) + ;; helm-mode passes NAME with an extra whitespace at the end. Since + ;; `julia--latexsub-start-symbol' won't include whitespace, we can safely + ;; strip whitespace. + (clean-name (string-clean-whitespace name)) + (symb (abbrev-symbol clean-name julia-latexsub-abbrev-table)) + (end (+ beg (length clean-name)))) (abbrev-insert symb name beg end))) #'ignore)) From 696dcd8eb842f21bb63dd7494ea852ee70d10601 Mon Sep 17 00:00:00 2001 From: Adam Beckmeyer Date: Fri, 15 Mar 2024 10:01:35 -0400 Subject: [PATCH 2/2] Use string-trim-right instead of string-clean-whitespace string-clean-whitespace does more than is needed and is provided by subr-x instead of just subr, so was causing tests to fail on older emacs versions. --- julia-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/julia-mode.el b/julia-mode.el index a702f1d..744515e 100644 --- a/julia-mode.el +++ b/julia-mode.el @@ -913,7 +913,7 @@ buffer where the LaTeX symbol starts." ;; helm-mode passes NAME with an extra whitespace at the end. Since ;; `julia--latexsub-start-symbol' won't include whitespace, we can safely ;; strip whitespace. - (clean-name (string-clean-whitespace name)) + (clean-name (string-trim-right name)) (symb (abbrev-symbol clean-name julia-latexsub-abbrev-table)) (end (+ beg (length clean-name)))) (abbrev-insert symb name beg end)))