Skip to content

Commit

Permalink
Remove old latexsub implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
non-Jedi committed Dec 6, 2022
1 parent 307b4af commit 4d20476
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 40 deletions.
44 changes: 33 additions & 11 deletions julia-mode-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -880,25 +880,47 @@ return fact(x)
end" 'end-of-defun "n == 0" "return fact(x)[ \n]+end" 'end 2))

;;;
;;; substitution tests
;;; latex completion tests
;;;

(defun julia--substitute (contents position)
"Call LaTeX subsitution in a buffer with `contents' at point
`position', and return the resulting buffer."
(defun julia--find-latex (contents position)
"Find bounds of LaTeX symbol in CONTENTS with point at POSITION."
(with-temp-buffer
(julia-mode)
(insert contents)
(goto-char position)
(julia-latexsub)
(cons (julia-mode--latexsub-start-symbol) (julia-mode--latexsub-end-symbol))))

(ert-deftest julia--test-find-latex ()
(should (equal (julia--find-latex "\\alpha " 7) (cons 1 7)))
(should (equal (julia--find-latex "\\alpha " 3) (cons 1 7)))
(should (equal (julia--find-latex "x\\alpha " 8) (cons 2 8)))
(should (equal (julia--find-latex "x\\alpha " 3) (cons 2 8)))
;; There is no valid substitution for \alpha(, but there could
;; be. julia-mode-latexsub-completion-at-point-before will still
;; give correct completion in this situation.
(should (equal (julia--find-latex "\\kappa\\alpha(" 13) (cons 7 14)))
(should (equal (julia--find-latex "\\kappa\\alpha(" 4) (cons 1 7))))

;;;
;;; abbrev tests
;;;

(defun julia--abbrev (contents position)
"Call `expand-abbrev' in buffer with CONTENTS at POSITION."
(with-temp-buffer
(julia-mode)
(abbrev-mode)
(insert contents)
(goto-char position)
(expand-abbrev)
(buffer-string)))

(ert-deftest julia--test-substitutions ()
(should (equal (julia--substitute "\\alpha " 7) "α "))
(should (equal (julia--substitute "x\\alpha " 8) ""))
(should (equal (julia--substitute "\\kappa\\alpha(" 13) "\\kappaα("))
(should (equal (julia--substitute "\\alpha" 7) "α"))
; (should (equal (julia--substitute "\\alpha" 6) "α")) ; BROKEN
(ert-deftest julia--test-latex-abbrev ()
(should (equal (julia--abbrev "\\alpha " 7) "α "))
(should (equal (julia--abbrev "x\\alpha " 8) ""))
(should (equal (julia--abbrev "\\kappa\\alpha(" 13) "\\kappaα("))
; (should (equal (julia--abbrev "\\alpha(" 6) "α")) ; BROKEN
)

;;; syntax-propertize-function tests
Expand Down
30 changes: 1 addition & 29 deletions julia-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -786,31 +786,6 @@ strings."
(define-key julia-mode-map (kbd "<backtab>") 'julia-manual-deindent)

;; (See Julia issue #8947 for why we don't use the Emacs tex input mode.)
(defun julia-latexsub ()
"Perform a LaTeX-like Unicode symbol substitution."
(interactive "*i")
(let ((orig-pt (point)))
(while (not (or (bobp) (= ?\\ (char-before))
(= ?\s (char-syntax (char-before)))))
(backward-char))
(if (and (not (bobp)) (= ?\\ (char-before)))
(progn
(backward-char)
(let ((sub (gethash (buffer-substring (point) orig-pt) julia-mode-latexsubs)))
(if sub
(progn
(delete-region (point) orig-pt)
(insert sub))
(goto-char orig-pt))))
(goto-char orig-pt))))

(defun julia-latexsub-or-indent (arg)
"Either indent according to mode or perform a LaTeX-like symbol substution"
(interactive "*i")
(if (julia-latexsub)
(indent-for-tab-command arg)))
(define-key julia-mode-map (kbd "TAB") 'julia-latexsub-or-indent)

(defun julia-mode--latexsub-start-symbol ()
"Determine the start location for LaTeX-like symbol at point.
If there is not a LaTeX-like symbol at point, return nil."
Expand Down Expand Up @@ -898,10 +873,7 @@ following commands are defined:
"Regexp for matching `inferior-julia' prompt.")

(defvar inferior-julia-mode-map
(let ((map2 (nconc (make-sparse-keymap) comint-mode-map)))
;; example definition
(define-key map2 (kbd "TAB") 'julia-latexsub-or-indent)
map2)
(nconc (make-sparse-keymap) comint-mode-map)
"Basic mode map for `inferior-julia-mode'.")

;;;###autoload
Expand Down

0 comments on commit 4d20476

Please sign in to comment.