diff options
author | Jesús <heckyel@hyperbola.info> | 2018-06-29 22:31:11 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2018-06-29 22:31:11 -0500 |
commit | 15ea85ee14a5c40a8ed40d66fe591fe528a8719d (patch) | |
tree | ecb241b06ffc1a3ab3e1b275c83d761d03b35fc8 /lisp/init-nlinum.el | |
download | emacs-base-15ea85ee14a5c40a8ed40d66fe591fe528a8719d.tar.lz emacs-base-15ea85ee14a5c40a8ed40d66fe591fe528a8719d.tar.xz emacs-base-15ea85ee14a5c40a8ed40d66fe591fe528a8719d.zip |
first commit
Diffstat (limited to 'lisp/init-nlinum.el')
-rw-r--r-- | lisp/init-nlinum.el | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/lisp/init-nlinum.el b/lisp/init-nlinum.el new file mode 100644 index 0000000..0e61eab --- /dev/null +++ b/lisp/init-nlinum.el @@ -0,0 +1,76 @@ +;;---------------------------------------------------------------------------- +;; Line numbers +;;---------------------------------------------------------------------------- +;; Linum snippets from: https://www.emacswiki.org/emacs/LineNumbers +(require-package 'nlinum) +(require 'linum) +(require 'hl-line) + +(defface my-linum-hl + `((t :inherit linum :background ,(face-background 'hl-line nil t))) + "Face for the current line number." + :group 'linum) +(add-hook 'linum-before-numbering-hook 'my-linum-get-format-string) + +(defun my-linum-get-format-string () + (let* ((width (1+ (length (number-to-string + (count-lines (point-min) (point-max)))))) + (format (concat "%" (number-to-string width) "d \u2502"))) + (setq my-linum-format-string format))) + +(defvar my-linum-current-line-number 0) + +(defun my-linum-format (line-number) + (propertize (format my-linum-format-string line-number) 'face + (if (eq line-number my-linum-current-line-number) + 'my-linum-hl + 'linum))) +(setq linum-format 'my-linum-format) + +(defadvice linum-update (around my-linum-update) + (let ((my-linum-current-line-number (line-number-at-pos))) + ad-do-it)) +(ad-activate 'linum-update) + +(defvar *linum-mdown-line* nil) + +(defun line-at-click () + (save-excursion + (let ((click-y (cdr (cdr (mouse-position)))) + (line-move-visual-store line-move-visual)) + (setq line-move-visual t) + (goto-char (window-start)) + (next-line (1- click-y)) + (setq line-move-visual line-move-visual-store) + ;; If you are using tabbar substitute the next line with + ;; (line-number-at-pos)))) + (1+ (line-number-at-pos))))) + +(defun md-select-linum () + (interactive) + (goto-line (line-at-click)) + (set-mark (point)) + (setq *linum-mdown-line* + (line-number-at-pos))) + +(defun mu-select-linum () + (interactive) + (when *linum-mdown-line* + (let (mu-line) + ;; (goto-line (line-at-click)) + (setq mu-line (line-at-click)) + (goto-line (max *linum-mdown-line* mu-line)) + (set-mark (line-end-position)) + (goto-line (min *linum-mdown-line* mu-line)) + (setq *linum-mdown* + nil)))) + +(global-set-key (kbd "<left-margin> <down-mouse-1>") 'md-select-linum) +(global-set-key (kbd "<left-margin> <mouse-1>") 'mu-select-linum) +(global-set-key (kbd "<left-margin> <drag-mouse-1>") 'mu-select-linum) + +(add-hook 'find-file-hook (lambda () (linum-mode 1))) +(linum-mode) +(setq global-linum-mode t) + +(provide 'init-nlinum) |