Can I change the emacs view of the first column? (Zero to one)

The number of columns in the columns is Emacs column number from 0, which usually does not cause me grief, but I work with some data files based on rows / columns whose specification starts with "1", and it would be much simpler if I could either force emacs to do this, or find some elisp.

Thoughts are welcome.

+7
source share
3 answers

You cannot easily change Emacs to count columns based on 1, the change should be in C code.

However, you can calculate your own column and put it in the mode line. Note: this requires the use of force-mode-line-update , which can potentially slow down your Emacs (just keep this in mind if after two years Emacs is sluggish on some kind of large buffer).

 ;; update the mode line to have line number and column number (setq mode-line-position '("%p (%l," (:eval (format "%d)" (1+ (current-column)))))) ;; force the update of the mode line so the column gets updated (add-hook 'post-command-hook 'force-mode-line-update) 

Doc references use 'Variables Used in the Mode Bar' and 'Cursor Position Information' .

+9
source

Like Emacs 26 (not yet released), a built-in button will be created to fix it.

To use it, set (setq column-number-indicator-zero-based nil) in your .emacs

You can create emacs from the leading branch of the git repository to get this feature now.

+3
source

Well, that might not be the best answer, because I don't know emacs, which is good. I edited mode-line-position , which is part of mode-line-format . Before using it, look at the original value to know for sure that nothing is missing.

 (setq mode-line-position '((-3 #("%p" 0 2 (help-echo "Size indication mode mouse-1: Display Line and Column Mode Menu" mouse-face mode-line-highlight local-map (keymap (mode-line keymap (down-mouse-1 keymap (column-number-mode menu-item "Display Column Numbers" column-number-mode :help "Toggle displaying column numbers in the mode-line" :button (:toggle . column-number-mode)) (line-number-mode menu-item "Display Line Numbers" line-number-mode :help "Toggle displaying line numbers in the mode-line" :button (:toggle . line-number-mode)) "Toggle Line and Column Number Display")))))) (size-indication-mode (8 #(" of %I" 0 6 (help-echo "Size indication mode mouse-1: Display Line and Column Mode Menu" mouse-face mode-line-highlight local-map (keymap (mode-line keymap (down-mouse-1 keymap (column-number-mode menu-item "Display Column Numbers" column-number-mode :help "Toggle displaying column numbers in the mode-line" :button (:toggle . column-number-mode)) (line-number-mode menu-item "Display Line Numbers" line-number-mode :help "Toggle displaying line numbers in the mode-line" :button (:toggle . line-number-mode)) "Toggle Line and Column Number Display"))))))) "(%l,[%c" (:eval (format ",%d])" (1+ (current-column)))))) 

The main problem is that when removing %c (column number) from line mode, your (:eval (current-column)) is very slow. I do not know how to do it better.

+1
source

All Articles