2012-07-23 18 views
16

¿Es posible visualizar números de línea relativos en el margen derecho de un búfer de Emacs y mantener los números de línea normales en el margen izquierdo?Números de línea relativa de Emacs en el margen derecho

+4

Para aquellos familiarizados con la característica: [números de línea relativos en VIM] (http://jeffkreeftmeijer.com/2012/relative-line-numbers-in -vim-for-super-fast-movement /); – dotancohen

+0

Gracias @dotancohen! – Mike

+0

Nunca escuché emacs para tener números de línea relativos. – alinsoar

Respuesta

6

Esto puede ser un punto de partida. Cargue estas definiciones y haga M-xlinum-mode.

(defun linum-relative-right-set-margin() 
    "Make width of right margin the same as left margin" 
    (let* ((win (get-buffer-window)) 
    (width (car (window-margins win)))) 
    (set-window-margins win width width))) 

(defadvice linum-update-current (after linum-left-right-update activate) 
    "Advice to run right margin update" 
    (linum-relative-right-set-margin) 
    (linum-relative-right-update (line-number-at-pos))) 

(defadvice linum-delete-overlays (after linum-relative-right-delete activate) 
    "Set margins width to 0" 
    (set-window-margins (get-buffer-window) 0 0)) 

(defun linum-relative-right-update (line) 
    "Put relative numbers to the right margin" 
    (dolist (ov (overlays-in (window-start) (window-end))) 
    (let ((str (overlay-get ov 'linum-str))) 
     (if str 
     (let ((nstr (number-to-string 
       (abs (- (string-to-number str) line))))) 
     ;; copy string properties 
     (set-text-properties 0 (length nstr) (text-properties-at 0 str) nstr) 
     (overlay-put ov 'after-string 
      (propertize " " 'display `((margin right-margin) ,nstr)))))))) 

Ver la captura de pantalla

emacs screenshot

+0

Esto parece que encaja muy bien. Bien vale la pena la espera! ¡Bien hecho! – Mike

+0

Esto es bueno. Sin embargo, quiero que se muestre el linum absoluto a la derecha y el linum relativo a la izquierda (para que pueda tener el número de línea real junto con el plugin relativo a linum de ELPA). ¿Cómo puedo hacerlo? – Amumu

+0

ambos a la izquierda serían mejor que yo –

Cuestiones relacionadas