I am reviewing some code in emacs that has a series of for loops that span several pages. The indentations done by the author are poor so it is not easy to tell where loops begi
You can use forward-list
(C-M-n
) and backward-list
(C-M-p
) to navigate forward and backward over a parenthetical group. (Also try forward-sexp
(C-M-f
) and backward-sexp
(C-M-b
)).
Check out the EmacsWiki on Navigating Parentheses, the Emacs manual node on matching paretheses, and this SO thread on matching brackets.
I think you're looking for the wrong solution.
Place your cursor on loops starting parenthesis or curly bracket and press C-M-n This runs the command forward-list
which will jump your cursor to the matching end paren or curly brace.
Open the buffer, move to the starting paren, use C-x 3 to split the window in half, move to the new window, and use forward-list
now you should have the starting paren in view on the left and the ending paren in view on the right.
Alternatively, use hideshow to collapse blocks of code inside the loop to shrink the size and potentially fit it on one screen.
Also look into follow-mode
this will allow you to view one buffer in multiple windows continuously effectively doubling or tripling the number of continuous lines of code you can see. This will work with show-paren-mode
.
Also if the indentation is really so terrible, run mark-whole-buffer
and indent-region
to fix it up.
Here is a modification of https://github.com/nschum/highlight-parentheses.el/blob/master/highlight-parentheses.el, which will permit you to scroll up or down without deleting the overlays. You can add additional this-command
statements to suit your needs.
(defun hl-paren-highlight ()
"Highlight the parentheses around point."
(unless
(or
(eq this-command 'mwheel-scroll)
(eq this-command 'scroll-up)
(eq this-command 'scroll-down))
(unless (= (point) hl-paren-last-point)
(setq hl-paren-last-point (point))
(let ((overlays hl-paren-overlays)
pos1 pos2
(pos (point)))
(save-excursion
(condition-case err
(while (and (setq pos1 (cadr (syntax-ppss pos1)))
(cdr overlays))
(move-overlay (pop overlays) pos1 (1+ pos1))
(when (setq pos2 (scan-sexps pos1 1))
(move-overlay (pop overlays) (1- pos2) pos2)
))
(error nil))
(goto-char pos))
(dolist (ov overlays)
(move-overlay ov 1 1))))))