Emacs: line numbers that relate to line wrappers

Modes : I use linum for line numbers related to the linear packet number for relative line numbers. If that matters, I also use visual-linear mode. They are flexible.

Currently, one line (i.e. text without a new line) is numbered as only one line, no matter how many times it is wrapped. I am wondering if there is a way to renumber to respect these wrappers. For example,

263 This is all in a single line without newlines 

can be:

 263 This is all in 264 a single line 265 without newlines 

and in relative mode:

 0 This is all in a single line without newlines 

can be:

 -1 This is all in 0 a single line 1 without newlines 

I really only need to change the relative mode, but do not mind if it goes into absolute mode.

Switching, which works on both, would be very useful - thus, the user can specifically choose when or with what modes to disable or enable it.

+4
source share
1 answer

If the goal is navigation, I suggest a similar solution using the popular ace-jump-mode .

If the goal is only constant line numbering, you can consider longlines-mode instead of visual-line-mode (but I would personally avoid this).

ace-jump @GitHub
https://github.com/winterTTr/ace-jump-mode

Demo:
http://dl.dropboxusercontent.com/u/3254819/AceJumpModeDemo/AceJumpDemo.htm

With it, you can go to any line in just two keystrokes.

In addition to the lines, you can go to the beginning of any word; there is also individual jump accuracy at the character level. If desired, it can be configured to limit transitions to the current window / buffer or to all windows in the current frame and even to several frames.

However, he does not recognize wrapped lines as places available for transitions. Again, you can consider longlines-mode as a fix for this, if it is really important for you, but, as I understand it, it is considered a hacker and is outdated in favor of visual-line-mode . Although, with longlines-mode , the lines are renumbered exactly as you want in the first example.

I suppose the goal is navigation, and I suppose you will find just a little practice that word hopping or even jumping through incremental searches is an excellent solution.

Update

Here's a simple ace-jump trick solution for scanning in N lines using emacs narrowing functions; perhaps others can improve it. You can also do something similar for text and linear modes.

 (defun brian-ace-jump-to-char-within-N-lines (&optional n) (interactive "p") (let* ((N (or n 0)) (query-char (read-char "Query Char:")) (start (save-excursion (forward-line (- N)) (point))) (stop (save-excursion (forward-line (1+ N)) (point)))) (unwind-protect (condition-case err (progn (narrow-to-region start stop) (ace-jump-char-mode query-char)) (error (message (error-message-string err)))) (widen)))) 
+4
source

Source: https://habr.com/ru/post/1489820/


All Articles