branch: elpa/julia-mode
commit d52cb3e8855c1b0926034312b76475f923570ddc
Author: Adam Beckmeyer <[email protected]>
Commit: Adam Beckmeyer <[email protected]>
Provide alternative to indent-for-tab-command for use with company
See comments for reasoning. This commit allows company-mode users to
comfortably press TAB
for completion of latex codes to unicode symbols. Previously,
indent-for-tab-command would
fallback to emacs' native completion UI instead of using company.
This commit also contains a slight cleanup to make the :exit-function more
robust to the
condition where abbrev-symbol fails.
---
julia-mode.el | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/julia-mode.el b/julia-mode.el
index f944dad284..466a547efc 100644
--- a/julia-mode.el
+++ b/julia-mode.el
@@ -38,6 +38,7 @@
(require 'cl-lib)
(require 'julia-mode-latexsubs)
+(eval-when-compile (require 'subr-x))
(defvar julia-mode-hook nil)
@@ -868,11 +869,24 @@ buffer where the LaTeX symbol starts."
;; `ivy-mode' always calls `:exit-function' with `sole' and not
`finished' (see
;; <https://github.com/abo-abo/swiper/issues/2345>). Instead of
automatic
;; expansion, user can either enable `abbrev-mode' or call
`expand-abbrev'.
- (when (eq status 'finished)
- (abbrev-insert (abbrev-symbol name julia-latexsub-abbrev-table) name
- beg (point))))
+ (when-let (((eq status 'finished))
+ (symb (abbrev-symbol name julia-latexsub-abbrev-table)))
+ (abbrev-insert symb name beg (point))))
#'ignore))
+;; company-mode doesn't work via `indent-for-tab-command'. In order to have a
consistent
+;; completion UI, we must dynamically choose between
`company-indent-or-complete-common' and
+;; `indent-for-tab-command' based on whether `company-mode' is active.
+(with-eval-after-load 'company
+ (defun julia-company-indent-for-tab-command (arg)
+ "Call `indent-for-tab-command' or `company-indent-or-complete-common' as
appropriate."
+ (interactive "P")
+ (if company-mode
+ (company-indent-or-complete-common arg)
+ (indent-for-tab-command arg)))
+ (define-key julia-mode-map [remap indent-for-tab-command]
+ #'julia-company-indent-for-tab-command))
+
;; Math insertion in julia. Use it with
;; (add-hook 'julia-mode-hook 'julia-math-mode)
;; (add-hook 'inferior-julia-mode-hook 'julia-math-mode)