Skip to content

Commit

Permalink
Don't error if the first line of the file is empty.
Browse files Browse the repository at this point in the history
We can't go back before (point-min), and Emacs errors if we try.
  • Loading branch information
Wilfred committed Nov 11, 2014
1 parent 468c2a2 commit f20e3d9
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions contrib/julia-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ Handles both single-line and multi-line comments."
(cond
((julia-in-comment) nil)
((julia-in-string) nil)
((<= (point) (1+ (point-min))) nil)
(:else
(save-excursion
;; See if point is inside a character, e.g. '|x'
Expand All @@ -242,17 +243,18 @@ Handles both single-line and multi-line comments."
(backward-char 1)
;; Move back one more character, as julia-char-regex checks
;; for whitespace/paren/etc before the single quote.
(backward-char 1)
(ignore-errors (backward-char 1)) ; ignore error from being at (point-min)

(if (looking-at julia-char-regex)
t
;; If point was in a \ character (i.e. we started at '\|\'),
;; we need to move back once more.
(if (looking-at (rx "'\\"))
(progn
(backward-char 1)
(looking-at julia-char-regex))
nil))))))
(ignore-errors
(if (looking-at (rx "'\\"))
(progn
(backward-char 1)
(looking-at julia-char-regex))
nil)))))))

(defun julia-in-brackets ()
"Return non-nil if point is inside square brackets."
Expand Down Expand Up @@ -322,6 +324,12 @@ Do not move back beyond MIN."
(goto-char pos)
(+ julia-basic-offset (current-indentation))))))

(defsubst julia--safe-backward-char ()
"Move back one character, but don't error if we're at the
beginning of the buffer."
(unless (eq (point) (point-min))
(backward-char)))

(defun julia-paren-indent ()
"Return the column position of the innermost containing paren
before point. Returns nil if we're not within nested parens."
Expand All @@ -339,7 +347,7 @@ before point. Returns nil if we're not within nested parens."
((looking-at (rx (any "]" ")")))
(decf open-count)))))

(backward-char))
(julia--safe-backward-char))

(if (plusp open-count)
(+ (current-column) 2)
Expand All @@ -364,14 +372,15 @@ before point. Returns nil if we're not within nested parens."
(ignore-errors (+ (julia-last-open-block (point-min))
(if endtok (- julia-basic-offset) 0)))))
;; If the previous line ends in =, increase the indent.
(save-excursion
(if (and (not (equal (point-min) (line-beginning-position)))
(progn
(forward-line -1)
(end-of-line) (backward-char 1)
(equal (char-after (point)) ?=)))
(+ julia-basic-offset (current-indentation))
nil))
(ignore-errors ; if previous line is (point-min)
(save-excursion
(if (and (not (equal (point-min) (line-beginning-position)))
(progn
(forward-line -1)
(end-of-line) (backward-char 1)
(equal (char-after (point)) ?=)))
(+ julia-basic-offset (current-indentation))
nil)))
;; Otherwise, use the same indentation as previous line.
(save-excursion (forward-line -1)
(current-indentation))
Expand Down

0 comments on commit f20e3d9

Please sign in to comment.