[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/julia-mode 8078bb9d88 01/22: Add completion-at-point funct
|
From: |
ELPA Syncer |
|
Subject: |
[nongnu] elpa/julia-mode 8078bb9d88 01/22: Add completion-at-point functions for completing LaTeX strings |
|
Date: |
Thu, 4 May 2023 11:00:50 -0400 (EDT) |
branch: elpa/julia-mode
commit 8078bb9d88d1e388efd0a740d75cf1fce8e6c208
Author: Adam Beckmeyer <adam_gpg@thebeckmeyers.xyz>
Commit: Adam Beckmeyer <adam_gpg@thebeckmeyers.xyz>
Add completion-at-point functions for completing LaTeX strings
This is a version of #82 without the usage of :exit-function to
replace the LaTeX string with a unicode symbol.
---
julia-mode.el | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 56 insertions(+), 1 deletion(-)
diff --git a/julia-mode.el b/julia-mode.el
index 9e2c1207e7..cbd6f39112 100644
--- a/julia-mode.el
+++ b/julia-mode.el
@@ -774,6 +774,12 @@ Return nil if point is not in a function, otherwise point."
(setq-local indent-line-function #'julia-indent-line)
(setq-local beginning-of-defun-function #'julia-beginning-of-defun)
(setq-local end-of-defun-function #'julia-end-of-defun)
+ ;; If completion before point has higher priority than around, \lamb
+ ;; can get completed to \lambdamb
+ (add-hook 'completion-at-point-functions
+ #'julia-mode-latexsub-completion-at-point-before nil t)
+ (add-hook 'completion-at-point-functions
+ #'julia-mode-latexsub-completion-at-point-around nil t)
(setq indent-tabs-mode nil)
(setq imenu-generic-expression julia-imenu-generic-expression)
(imenu-add-to-menubar "Imenu"))
@@ -812,6 +818,51 @@ strings."
(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."
+ (save-excursion
+ ;; move backward until character can't be part of LaTeX, whitespace or
beginning of file
+ (while (not (or (bobp)
+ (= ?\\ (char-before))
+ ;; Checks char not in whitespace, comment, or
+ ;; escape. This works better than checking char is
+ ;; in word constitutents (?w) because things like
+ ;; "\^(", "\1/", and "\^=)" are valid.
+ (member (char-syntax (char-before)) '(?\s ?< ?> ?\\))))
+ (backward-char))
+ (when (= ?\\ (char-before))
+ (- (point) 1))))
+
+(defun julia-mode--latexsub-end-symbol ()
+ "Determine the end location for LaTeX-like symbol at point."
+ (save-excursion
+ (while (not (or (eobp)
+ (member (char-syntax (char-after)) '(?\s ?< ?> ?\\))))
+ (forward-char))
+ (point)))
+
+;; Sometimes you want to complete a symbol point is in middle of
+(defun julia-mode-latexsub-completion-at-point-around ()
+ "Return completion for LaTeX-like symbol around point.
+Suitable for use in `completion-at-point-functions'."
+ (let ((beg (julia-mode--latexsub-start-symbol)))
+ (when beg
+ (list beg (julia-mode--latexsub-end-symbol) julia-mode-latexsubs
+ :exclusive 'no
+ :annotation-function #'(lambda (s)
+ (concat " " (gethash s
julia-mode-latexsubs)))))))
+
+;; Sometimes you want to complete a symbol point is at end of (with no space
after)
+(defun julia-mode-latexsub-completion-at-point-before ()
+ "Return completion for LaTeX-like symbol before point.
+Suitable for use in `completion-at-point-functions'."
+ (let ((beg (julia-mode--latexsub-start-symbol)))
+ (when beg
+ (list beg (point) julia-mode-latexsubs :exclusive 'no
+ :annotation-function #'(lambda (s)
+ (concat " " (gethash s
julia-mode-latexsubs)))))))
+
;; Math insertion in julia. Use it with
;; (add-hook 'julia-mode-hook 'julia-math-mode)
;; (add-hook 'inferior-julia-mode-hook 'julia-math-mode)
@@ -888,7 +939,11 @@ following commands are defined:
(setq-local comint-prompt-read-only t)
(setq-local font-lock-defaults '(julia-font-lock-keywords t))
(setq-local paragraph-start julia-prompt-regexp)
- (setq-local indent-line-function #'julia-indent-line))
+ (setq-local indent-line-function #'julia-indent-line)
+ (add-hook 'completion-at-point-functions
+ #'julia-mode-latexsub-completion-at-point-before nil t)
+ (add-hook 'completion-at-point-functions
+ #'julia-mode-latexsub-completion-at-point-around nil t))
(add-hook 'inferior-julia-mode-hook #'inferior-julia--initialize)
- [nongnu] elpa/julia-mode updated (a20367f282 -> 7e301f4414), ELPA Syncer, 2023/05/04
- [nongnu] elpa/julia-mode 8078bb9d88 01/22: Add completion-at-point functions for completing LaTeX strings,
ELPA Syncer <=
- [nongnu] elpa/julia-mode 307b4afa9a 03/22: Create julia-mode-abbrev-table filled with latexsub abbrevs, ELPA Syncer, 2023/05/04
- [nongnu] elpa/julia-mode d52cb3e885 10/22: Provide alternative to indent-for-tab-command for use with company, ELPA Syncer, 2023/05/04
- [nongnu] elpa/julia-mode 77ff4f1146 15/22: comment code, fix docstring width, ELPA Syncer, 2023/05/04
- [nongnu] elpa/julia-mode d684bf172a 17/22: further byte compilation docstring warning fixes, ELPA Syncer, 2023/05/04
- [nongnu] elpa/julia-mode 759e8a8e57 18/22: Merge branch 'master' into tp/find-latexsub-end, ELPA Syncer, 2023/05/04
- [nongnu] elpa/julia-mode c87949315f 02/22: Remove hack for indentation in strings, ELPA Syncer, 2023/05/04
- [nongnu] elpa/julia-mode 4d2047666f 04/22: Remove old latexsub implementation, ELPA Syncer, 2023/05/04
- [nongnu] elpa/julia-mode 0160fecf90 05/22: Override TAB to do completion in julia-mode buffers, ELPA Syncer, 2023/05/04
- [nongnu] elpa/julia-mode f92227a87f 09/22: Fix whitespace, ELPA Syncer, 2023/05/04
- [nongnu] elpa/julia-mode f359fd01c5 12/22: Add predicate to "around" latex symbol completion, ELPA Syncer, 2023/05/04