branch: elpa/julia-mode
commit cdff61a0e6c102f04312638d46fe54c00b0fea0f
Author: Tamás K. Papp <tkp...@gmail.com>
Commit: Tamás K. Papp <tkp...@gmail.com>

    Fix julia--find-latex erroring when called at the beginning of buffer.
    
    Add a test for this case (which failed previously).
---
 julia-mode-tests.el | 12 +++++++-----
 julia-mode.el       |  2 +-
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/julia-mode-tests.el b/julia-mode-tests.el
index b6b2969eaf..69436de70c 100644
--- a/julia-mode-tests.el
+++ b/julia-mode-tests.el
@@ -913,14 +913,15 @@ end" 'julia-end-of-defun "function f(x)" "return fact(x)[ 
\n]+end" 'end))
 ;;;
 
 (defun julia--find-latex (contents position)
-  "Find bounds of LaTeX symbol in CONTENTS with point at POSITION, `'((start . 
end) string)'."
+  "Find bounds of LaTeX symbol in CONTENTS with point at POSITION, `'((start . 
end) string)'. Return NIL if no symbol is found."
   (with-temp-buffer
     (julia-mode)
     (insert contents)
     (goto-char position)
-    (let* ((beg (julia--latexsub-start-symbol))
-           (end (julia-mode--latexsubs-longest-partial-end beg)))
-      (list (cons beg end) (buffer-substring beg end)))))
+    (let ((beg (julia--latexsub-start-symbol)))
+      (when beg
+        (let ((end (julia-mode--latexsubs-longest-partial-end beg)))
+          (list (cons beg end) (buffer-substring beg end)))))))
 
 (ert-deftest julia--test-find-latex ()
   (should (equal (julia--find-latex "\\alpha " 7) '((1 . 7) "\\alpha")))
@@ -929,7 +930,8 @@ end" 'julia-end-of-defun "function f(x)" "return fact(x)[ 
\n]+end" 'end))
   (should (equal (julia--find-latex "x\\alpha " 3) '((2 . 8) "\\alpha")))
   (should (equal (julia--find-latex "\\kappa\\alpha(" 13) '((7 . 13) 
"\\alpha")))
   (should (equal (julia--find-latex "\\kappa\\alpha(" 4) '((1 . 7) "\\kappa")))
-  (should (equal (julia--find-latex "α\\hat_mean" 3) '((2 . 6) "\\hat"))))
+  (should (equal (julia--find-latex "α\\hat_mean" 3) '((2 . 6) "\\hat")))
+  (should (not (julia--find-latex "   later" 1))))
 
 ;;;
 ;;; abbrev tests
diff --git a/julia-mode.el b/julia-mode.el
index 78f4021072..66cd5e4f04 100644
--- a/julia-mode.el
+++ b/julia-mode.el
@@ -884,7 +884,7 @@ If there is not a LaTeX-like symbol at point, return nil."
                     ;; "\^(", "\1/", and "\^=)" are valid.
                     (member (char-syntax (char-before)) '(?\s ?< ?> ?\\))))
       (backward-char))
-    (when (= ?\\ (char-before))
+    (when (and (not (bobp)) (= ?\\ (char-before)))
       (- (point) 1))))
 
 ;; Sometimes you want to complete a symbol `point' is in middle of

Reply via email to