As @eric-brown mentioned you can use M-x linum-mode.
Another good idea is to use (add-hook 'prog-mode-hook 'linum-mode) in your init.el to automatically enable linum-mode in all programming modes.
For Emacs version >= 26 you can use display-line-numbers-mode or global-display-line-numbers-mode.
(string-to-number (format-mode-line "%l"))
You can extract other information using %-Constructs described in the Emacs Lisp Manual.
In addition to limitations pointed out by wasamasa and Stefan (see comments below) this does not work for buffers that are not displayed.
(dotimes (i 10000)
(insert (format "%...
Emacs provides a good amount of debugging facilities including M-x toggle-debug-on-error, M-x toggle-debug-on-quit, debug on signal (which can be used by sending USR2 to Emacs from outside), debug-on-entry (of a function), debug-on-message (when seeing a specific regexp match of a message) and finally, debug itself as alternative to instrumenting a function ...
Like most terminals, Emacs' term has a scrollback limit -- which will naturally mess with the consistency of linum's counting, as lines will be deleted from the beginning of the buffer.
The term-buffer-maximum-size variable controls this, and sure enough it has a default value of 2048.
So linum was telling you the truth: the terminal buffer was never more ...
If you are using Emacs 26 or newer, you can use display-line-numbers-mode.
** Emacs now supports optional display of line numbers in the buffer. This is similar to what 'linum-mode' provides, but much faster and
doesn't usurp the display margin for the line numbers. Customize the
buffer-local variable 'display-line-numbers' to ...
You can customize how to display the number. For example, define the following function that formats numbers as 003::
(defun jp-rel-format (offset)
"Another formatting function"
(format "%03d: " (abs offset)))
Then customize the variable relative-line-numbers-format to use this new function instead of the default realtive-line-numbers-default-format.
If you're using relative-line-numbers-mode, you can customize the formatting to get what you want:
(defun relative-abs-line-numbers-format (offset)
"The default formatting function.
Return the absolute value of OFFSET, converted to string."
(if (= 0 offset)
(number-to-string (abs offset))))
If the user is not getting the line number multiple times each command loop for various positions, then using line-number-at-pos is sufficient -- it will get a line number even if point is not visible: (line-number-at-pos (window-start))
If the user is getting the line number multiple times each command loop for various positions, then it can be much ...
Because the last line hasn't started yet. Adding newline symbol to the end makes the cursor jump from the current line to the next one, but it doesn't add anything to it (new one). Strictly speaking, it is not a line yet.
Supposing that every newline symbol was visible, you would get
nlinum.el uses the following:
(defvar nlinum--line-number-cache nil)
;; We could try and avoid flushing the cache at every change, e.g. with:
;; (defun nlinum--before-change (start _end)
;; (if (and nlinum--line-number-cache
;; (< start (car nlinum--line-number-cache)))
In order for your changes to persist, you need to add them to your init file. If you've used any customize functionality, it probably generated one for you, and it's saved in ~/.emacs. If that isn't the case, you're better off putting it in ~/.emacs.d/init.el.
In order to have line numbers in all buffers and have them persistently, you can put
display-line-numbers is a buffer-local variable. To enable line numbers for only certain modes, do not use setq-default. Instead, use setq ... something like this:
(add-hook 'prog-mode-hook (lambda () (setq display-line-numbers 'relative)))
Or, use a preferred major-mode hook such as the perl-mode-hook or html-mode-hook:
nlinum-mode is another option. It has the same interface as linum-mode, so you can use the same hooks, but it uses a different technology to be more performant. Quote from nlinum.el:
;; This is like linum-mode, but uses jit-lock to be (hopefully) more efficient.
You can install it via GNU Elpa via the usual list-packages.
Maybe because it's 2018 now, but in my case,
I only had to turn on debugging like wasamasa suggested:
After this, M-x eval-buffer on my faulty Elisp file
gave context by providing the position of the error,
Debugger entered--Lisp error: (invalid-read-syntax ")")
eval-buffer() ; Reading at buffer position 523
A little late, but here's what I have in my .emacs. It does change the numbering for all linum-mode enabled buffers, but that's what I generally want:
(defvar my-linum-base-line nil)
(defvar my-linum-format nil)
org-map-entries is a great function for this sort of thing:
(org-map-entries FUNC &optional MATCH SCOPE &rest SKIP)
Call FUNC at each headline selected by MATCH in SCOPE.
To do what you outlined above from within the target file it's simply a matter of:
(org-map-entries (lambda () (line-number-at-pos)) nil 'file)
To only enable line numbers in "buffers that have code", you could add a hook to prog-mode-hook:
(add-hook 'prog-mode-hook #'display-line-numbers-mode)
(or whatever line numbering mode/function you're using), and make sure you don't have global-display-line-numbers-mode somewhere in your init. However, "buffers with filenames" and "buffers with code" don't ...
There are a few ways to do this -- my preferred method is to set the frame defaults for the fringes:
(set-face-attribute 'fringe nil :background "red")
(add-to-list 'default-frame-alist '(left-fringe . 11))
(add-to-list 'default-frame-alist '(right-fringe . 0))
It is possible to set the windows fringes globally:
(setq-default left-fringe-width 11)
The "visual line number, counting from point-min" depends on the window width, font choice, font size, etc... so a given buffer's position can have several different "visual line numbers" at the same time if it's displayed in different windows.
So Emacs does not really try to provide this info.
OTOH you can easily get the "visual line number, counting from ...
Personally, I doubt the buffer implementation can be blamed for every performance problem people encounter with buffers. My specific problem with it did involve long lines that were slowing down redisplay, a known issue with a multitude of reasons behind it, including Bidi rendering, excessive movement of point crossing the problematic line and less than ...
I think those screenshots are actually of vim, in which case all you need to do is :set rnu.
For emacs, you're looking for linum-relative.
I have various hacks you might be interested, which makes the emulation of rnu closer:
(set-face-background 'linum nil)
;; truncate current line to four ...
GNU bug report logs - #28247; Display native line number on last line of buffer (when empty line): https://debbugs.gnu.org/cgi/bugreport.cgi?bug=28247
Q: "Emacs does not display a native line number on the last line of the buffer unless there is something there in addition to the cursor. What would be a good approach to modifying the C code to draw a ...
This is not an insanely short snippet but it should work. Highlight a region and run this command:
(defun number-region (start end)
(narrow-to-region start end)
(let ((counter 0))
(while (re-search-forward "^" nil t)
(setq counter (+ 1 counter))
Specifically for the built-in line-number support in Emacs 26.1:
display-line-numbers-widen is a variable defined in `xdisp.c'.
Its value is nil
Automatically becomes buffer-local when set.
Calls these functions when changed: (#<subr set-buffer-redisplay>)
Non-nil means display line numbers disregarding any narrowing.
A rather naive solution - there should be no leading numbers of a paragraph with a different --textual-- meaning:
Edited after request: When starting from an already numbered paragraph, take that value counting on.
(defun number-paragraphs (&optional takefirst)
"Numbers resp. renumber paragraphs.
If starting from already numbered, take that value ...