Emacs how to show only the lines on or before the cursor in a file
Asked Answered
I

2

5

I am a high school computer science teacher and would like to use emacs to present programs to my students. I would like to be able to present the programs, even short ones, one line at a time and not have the whole program show in the emacs buffer from the start.

Thus I would like emacs to hide all the lines below the current line and reveal each line when I move the cursor down to that line.

Ise answered 15/5, 2014 at 12:11 Comment(0)
C
3

Inspired by your question, I added library reveal-next.el to EmacsWiki. I think it does what you want.

Concinnate answered 16/5, 2014 at 15:17 Comment(2)
Putting the following in my init.el, I was also able to add highlighting of the current line. Thanks. (load-file "~/.emacs.d/reveal-next.el") (defun hide-following-code () (interactive) (hl-line-mode t) (reveal-next-mode t)) (global-set-key (kbd "C-<down>") 'hide-following-code)Ise
That just highlights the last line showing, no? BTW, did you notice that if you set reveal-next-char-level to t then you can hide/reveal things smaller or bigger than just a line at a time. E.g, you can use C-M-f to move forward a sexp, revealing it etc. Anyway, HTH.Concinnate
D
6

Try this:

(defun narrow-next-line ()
  (interactive)
  (widen)
  (call-interactively 'move-end-of-line)
  (forward-char)
  (call-interactively 'move-end-of-line)
  (narrow-to-region 1 (point)))

(global-set-key (kbd "C-x n i") 'narrow-next-line)

Choose your own hotkey for this command. See also http://www.gnu.org/software/emacs/manual/html_node/emacs/Narrowing.html

Decolorize answered 15/5, 2014 at 13:32 Comment(0)
C
3

Inspired by your question, I added library reveal-next.el to EmacsWiki. I think it does what you want.

Concinnate answered 16/5, 2014 at 15:17 Comment(2)
Putting the following in my init.el, I was also able to add highlighting of the current line. Thanks. (load-file "~/.emacs.d/reveal-next.el") (defun hide-following-code () (interactive) (hl-line-mode t) (reveal-next-mode t)) (global-set-key (kbd "C-<down>") 'hide-following-code)Ise
That just highlights the last line showing, no? BTW, did you notice that if you set reveal-next-char-level to t then you can hide/reveal things smaller or bigger than just a line at a time. E.g, you can use C-M-f to move forward a sexp, revealing it etc. Anyway, HTH.Concinnate

© 2022 - 2024 — McMap. All rights reserved.