Skip to content

Commit

Permalink
Strip whitespace in latexsub :exit-function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
non-Jedi committed Mar 15, 2024
1 parent 72370db commit 20a95d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions julia-mode-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -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) ""))
;; 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 "))
Expand Down
8 changes: 6 additions & 2 deletions julia-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,12 @@ buffer where the LaTeX symbol starts."
;; <https://github.com/abo-abo/swiper/issues/2345>). 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))

Expand Down

0 comments on commit 20a95d6

Please sign in to comment.