Skip to content

Commit

Permalink
Extensive notes; wrap body in save-excursion
Browse files Browse the repository at this point in the history
Originally, all of these functions were inside one huge save-excursion form. To
my surprise, they typically need their _own_ save excursion wrapping to make
sure everything is consistent, particularly under test.

Also added, a great deal of notes about the function itself and how it works.
  • Loading branch information
Gastove committed Oct 29, 2019
1 parent d7e6c58 commit 360f380
Showing 1 changed file with 51 additions and 31 deletions.
82 changes: 51 additions & 31 deletions fsharp-mode-structure.el
Expand Up @@ -570,40 +570,60 @@ This function is normally bound to `indent-line-function' so
)))


;; NOTE[gastove|2019-10-25] An interesting point: this function is *only* ever
;; called if `open-bracket-pos' is non-nil; `open-bracket-pos' is generated by
;; `fsharp-nesting-level', which *only* returns non nil for non-string
;; characters. And yet: we don't just rely on `open-bracket-pos' as we compute
;; indentation, and I'm honestly not sure why.
(defun fsharp--compute-indentation-open-bracket (open-bracket-pos)
"Computes indentation for a line within an open bracket expression."
(let ((startpos (point))
placeholder)
;; align with first item in list; else a normal
;; indent beyond the line with the open bracket
(goto-char (1+ open-bracket-pos)) ; just beyond bracket
;; is the first list item on the same line?
(skip-chars-forward " \t")
(if (and (null (memq (following-char) '(?\n ?# ?\\)))
(not fsharp-conservative-indentation-after-bracket))
(save-excursion
(let ((startpos (point))
placeholder)
;; align with first item in list; else a normal
;; indent beyond the line with the open bracket
(goto-char (1+ open-bracket-pos)) ; just beyond bracket
;; NOTE[gastove|2019-10-25] -- consider switching to a forward regexp search
;; with a whitepsace character class.
;; is the first list item on the same line?
(skip-chars-forward " \t")
(if (and (null (memq (following-char) '(?\n ?# ?\\)))
(not fsharp-conservative-indentation-after-bracket))
; yes, so line up with it
(current-column)
;; first list item on another line, or doesn't exist yet
(forward-line 1)
(while (and (< (point) startpos)
(looking-at "[ \t]*\\(//\\|[\n\\\\]\\)")) ; skip noise
(forward-line 1))
(if (and (< (point) startpos)
(/= startpos
(save-excursion
(goto-char (1+ open-bracket-pos))
(forward-comment (point-max))
(point))))
;; again mimic the first list item
(current-indentation)
;; else they're about to enter the first item
(goto-char open-bracket-pos)
(setq placeholder (point))
(fsharp-goto-initial-line)
(fsharp-goto-beginning-of-tqs
(save-excursion (nth 3 (parse-partial-sexp
placeholder (point)))))
(+ (current-indentation) fsharp-indent-offset)))))
(current-column)
;; here follows the else
;; first list item on another line, or doesn't exist yet
;; TODO[gastove|2019-10-25] this needs to skip past whitespace, newlines,
;; *and* comments. I'm not convinced it does.
(forward-line 1)
(while (and (< (point) startpos)
(looking-at "[ \t]*\\(//\\|[\n\\\\]\\)")) ; skip noise
(forward-line 1))
(if (and (< (point) startpos)
(/= startpos
(save-excursion
(goto-char (1+ open-bracket-pos))
(forward-comment (point-max))
(point))))
;; again mimic the first list item
(current-indentation)
;; else they're about to enter the first item

;; NOTE[gastove|2019-10-25] Okay, this is all really hard to follow, but
;; I *think* what's going on here is:
;; - We go to the position of the opening bracket we're trying to compute indentation against.
;; - We set placeholder to point (meaning we set `placeholder' to `open-bracket-pos')
;; - We call a function that claims to go to the first line of a statement
;; - We call a function that I *believe* tries to take us to the opening delimiter of a matched pair
;; - We return the current indentation of *that*, plus indent offset
;; ... holy moly.
(goto-char open-bracket-pos)
(setq placeholder (point))
(fsharp-goto-initial-line)
(fsharp-goto-beginning-of-tqs
(save-excursion (nth 3 (parse-partial-sexp
placeholder (point)))))
(+ (current-indentation) fsharp-indent-offset))))))


(defun fsharp--compute-indentation-continuation-line ()
Expand Down

0 comments on commit 360f380

Please sign in to comment.