2012-07-23 23 views
16

Có thể hiển thị số dòng tương đối trên lề phải của bộ đệm Emacs và giữ số dòng bình thường trên lề trái không?Số dòng tương đối Emacs ở lề phải

+4

Đối với những người không quen với các tính năng: [số dòng tương đối trong VIM] (http://jeffkreeftmeijer.com/2012/relative-line-numbers-in -vim-for-super-fast-movement /); – dotancohen

+0

Cảm ơn @dotancohen! – Mike

+0

Tôi chưa bao giờ nghe thấy emacs để có số dòng tương đối. – alinsoar

Trả lời

6

Đây có thể là điểm khởi đầu. Tải định nghĩa này và làm 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)))))))) 

Xem ảnh chụp màn hình

emacs screenshot

+0

Điều này có vẻ như nó phù hợp với hóa đơn độc đáo. Cũng đáng để chờ đợi! Làm tốt! – Mike

+0

Điều này thật tuyệt. Tuy nhiên, tôi muốn linum tuyệt đối được hiển thị trên bên phải và linum tương đối ở bên trái (vì vậy tôi có thể có số dòng thực cùng với các plugin liên quan đến linum từ ELPA). Tôi làm nó như thế nào? – Amumu

+0

cả hai bên trái sẽ là imo tốt hơn –

Các vấn đề liên quan