From 52a86d626b76dabe227498f402d1c20692dd8ae8 Mon Sep 17 00:00:00 2001 From: Peng Li Date: Tue, 11 Aug 2015 21:16:24 +0800 Subject: [PATCH] emacs: add init-linu.el show current line number in relative mode --- emacs.d/config/init-linum.el | 37 +++++++++++++++++++++++++++ emacs.d/init.el | 59 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 emacs.d/config/init-linum.el diff --git a/emacs.d/config/init-linum.el b/emacs.d/config/init-linum.el new file mode 100644 index 0000000..684339f --- /dev/null +++ b/emacs.d/config/init-linum.el @@ -0,0 +1,37 @@ +;; refer to https://github.com/aaronbieber/dotfiles/blob/master/configs/emacs.d/lisp/init-linum.el +;;; Stuff for line numbers. +(defface linum-current + '((t (:inherit linum :weight bold :underline "#555"))) + "The current line number.") + +(defun my-linum-get-format-string () + (let* ((width (max 4 (1+ (length (number-to-string + (count-lines (point-min) (point-max))))))) + (format (concat "%" (number-to-string width) "d ")) + (current-line-format (concat "%-" (number-to-string width) "d "))) + (setq my-linum-format-string format) + (setq my-linum-current-line-format-string current-line-format))) + +(defvar my-linum-current-line-number 0) + +(setq linum-format 'my-linum-relative-line-numbers) + +(defun my-linum-relative-line-numbers (line-number) + (let* ((offset (abs (- line-number my-linum-current-line-number))) + (linum-display-value (if (= 0 offset) + my-linum-current-line-number + offset)) + (format-string (if (= my-linum-current-line-number line-number) my-linum-current-line-format-string my-linum-format-string)) + (face (if (= my-linum-current-line-number line-number) 'linum-current 'linum))) + (propertize (format format-string linum-display-value) 'face face))) + +(defadvice linum-update (around my-linum-update) + (let ((my-linum-current-line-number (line-number-at-pos))) + ad-do-it)) +(ad-activate 'linum-update) + +;;; Set up relative line numbering to mimic `:set number relativenumber`. +(global-linum-mode t) +(add-hook 'linum-before-numbering-hook 'my-linum-get-format-string) + +(provide 'init-linum) diff --git a/emacs.d/init.el b/emacs.d/init.el index ca3d88c..5441c95 100644 --- a/emacs.d/init.el +++ b/emacs.d/init.el @@ -231,6 +231,48 @@ ;; If there is more than one, they won't work right. '(fringe-mode (quote (4 . 0)) nil (fringe)) '(ggtags-split-window-function (quote split-window-vertically)) + '(hes-mode-alist + (quote + ((c-mode . "\\(\\\\\\([0-7]\\{1,3\\}\\|x[[:xdigit:]]+\\|u[[:xdigit:]]\\{4\\}\\|U[[:xdigit:]]\\{8\\}\\|[\"'?\\abfnrtv]\\)\\)") + (cperl-mode . "\\(\\\\\\([0-7]\\{1,3\\}\\|x[[:xdigit:]]+\\|u[[:xdigit:]]\\{4\\}\\|U[[:xdigit:]]\\{8\\}\\|[\"'?\\abfnrtv]\\)\\)") + (c++-mode . "\\(\\\\\\([0-7]\\{1,3\\}\\|x[[:xdigit:]]+\\|u[[:xdigit:]]\\{4\\}\\|U[[:xdigit:]]\\{8\\}\\|[\"'?\\abfnrtv]\\)\\)") + (objc-mode . "\\(\\\\\\([0-7]\\{1,3\\}\\|x[[:xdigit:]]+\\|u[[:xdigit:]]\\{4\\}\\|U[[:xdigit:]]\\{8\\}\\|[\"'?\\abfnrtv]\\)\\)") + (java-mode . "\\(\\\\\\([0-7]\\{1,3\\}\\|u[[:xdigit:]]\\{4\\}\\|[\"'\\bfnrt]\\)\\)") + (js-mode . "\\(\\\\\\([0-7]\\{1,3\\}\\|x[[:xdigit:]]\\{2\\}\\|u[[:xdigit:]]\\{4\\}\\|.\\)\\)") + (js2-mode . "\\(\\\\\\([0-7]\\{1,3\\}\\|x[[:xdigit:]]\\{2\\}\\|u[[:xdigit:]]\\{4\\}\\|.\\)\\)") + (ruby-mode + ("\\(\\\\\\([0-7]\\{1,3\\}\\|x[[:xdigit:]]\\{1,2\\}\\|u\\(?:[[:xdigit:]]\\{4\\}\\|{[[:xdigit:]]\\{1,6\\}\\(?:[[:space:]]+[[:xdigit:]]\\{1,6\\}\\)*}\\)\\|.\\)\\)" + (0 + (let* + ((state + (syntax-ppss)) + (term + (nth 3 state))) + (when + (or + (and + (eq term 39) + (member + (match-string 2) + (quote + ("\\" "'")))) + (if + (fboundp + (quote ruby-syntax-expansion-allowed-p)) + (ruby-syntax-expansion-allowed-p state) + (memq term + (quote + (34 47 10 96 t))))) + (add-face-text-property + (match-beginning 1) + (match-end 1) + (quote hes-escape-backslash-face)) + (add-face-text-property + (match-beginning 2) + (match-end 2) + (quote hes-escape-sequence-face)) + nil)) + prepend)))))) '(org-agenda-files (quote ("~/temp/org-note.org"))) '(powerline-text-scale-factor 0.85)) @@ -285,3 +327,20 @@ wg-mode-line-decor-divider ":") ;(workgroups-mode 1) +(defalias 'perl-mode 'cperl-mode) +;(setq cperl-invalid-face nil) + (setq cperl-invalid-face (quote off)) +;(add-hook 'prog-mode-hook '(lambda () +; (highlight-regexp "%[[:alpha:]]\\|\\\\[[:alpha:]]"))) + +(require 'highlight-escape-sequences) +(hes-mode) +;(setq cperl-font-lock t) +(put 'hes-escape-backslash-face 'face-alias 'font-lock-builtin-face) +(put 'hes-escape-sequence-face 'face-alias 'font-lock-builtin-face) + + +(add-to-list 'load-path "~/.emacs.d/Emacs-PDE-0.2.16/lisp/") +(load "pde-load") + +(require 'init-linum) -- 2.11.0