display-line-number.el (emacs中显示行号)
2008-12-05 12:27
387 查看
;;; display-line-number.el --- line number mode for Emacs
;; Copyright (C) 2004 Free Software Foundation, Inc.
;; Author: ChunYe Wang
;; Keywords: tools
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; Installation:
;; put the display-line-number.el in your load-path
;; (require 'display-line-number)
;; M-x display-line-number-mode
;; M-x display-line-number-mode-on
;; M-x display-line-number-mode-off
;;; Code:
(defvar display-line-number-mode nil
"Non-nil if display-line-number-mode is active in the current buffer.")
(make-variable-buffer-local 'display-line-number-mode)
(defvar display-line-number-face 'font-lock-keyword-face)
(defvar global-display-line-number-mode nil
"Non-nil if display-line-number-mode is active in the all buffer.")
(defvar display-line-number-format "%5d "
"String suitable for `format' that will generate a line number string.
`format' will be called with this string and one other argument
which will be an integer, the line number.")
(defun display-line-number-mode (&optional arg)
"Toggle display-line-number-mode.
With prefix argument, turn display-line-number-mode on if argument is positive.
When display-line-number-mode is enabled, a line number will appear at the left
margin of each line."
(interactive "P")
(if (null arg) (setq arg 0)
(setq arg (prefix-numeric-value arg)))
(cond
((> arg 0) (setq display-line-number-mode t))
((= arg 0) (setq display-line-number-mode
(not display-line-number-mode)))
((< arg 0) (setq display-line-number-mode nil)))
(if display-line-number-mode
(display-line-number-mode-on)
(display-line-number-mode-off)))
(defun global-display-line-number-mode (&optional arg)
"Toggle display-line-number-mode.
With prefix argument, turn display-line-number-mode on if argument is positive.
When display-line-number-mode is enabled, a line number will appear at the left
margin of each line."
(interactive "P")
(if (null arg) (setq arg 0)
(setq arg (prefix-numeric-value arg)))
(cond
((> arg 0) (setq global-display-line-number-mode t))
((= arg 0) (setq global-display-line-number-mode
(not global-display-line-number-mode)))
((< arg 0) (setq global-display-line-number-mode nil)))
(if global-display-line-number-mode
(add-hook 'find-file-hooks
'display-line-number-mode-on)
(remove-hook 'find-file-hooks
'display-line-number-mode-on))
(message "global display line number mode is %s" (if global-display-line-number-mode "on" "off")))
;; (global-display-line-number-mode (if global-display-line-number-mode 1 0))
(defun display-line-number-mode-on()
(interactive)
(setq display-line-number-mode t)
(dln-undisplay)
(dln-display)
(make-local-variable 'after-change-functions)
(make-local-variable 'window-scroll-functions)
(make-local-variable 'window-configuration-change-hook)
(add-to-list 'after-change-functions
'dln-after-change-function)
(add-to-list 'window-configuration-change-hook
'dln-window-configuration-change-function)
(add-to-list 'window-scroll-functions
'dln-window-scroll-function))
(defun display-line-number-mode-off()
(interactive)
(dln-undisplay)
(setq after-change-functions (remq
'dln-after-change-function
after-change-functions))
(setq window-configuration-change-hook (remq
'dln-window-configuration-change-function
window-configuration-change-hook))
(setq window-scroll-functions (remq
'dln-window-scroll-function
window-scroll-functions)))
(defun dln-core (start end str)
(let ((e (make-overlay start end)))
(overlay-put e 'before-string (propertize str 'face display-line-number-face))
(overlay-put e 'name 'dln-core)))
(defun dln-display ( &optional arg)
(interactive "p")
;; (setq left-margin-width 5)
;; (set-window-margins (selected-window) 5 0)
(let ((line-number 1)
(start (window-start (selected-window)))
(end (window-end (selected-window) t))
(n 0)
(flag 0))
(save-excursion
(save-restriction
(widen)
(goto-char start)
(beginning-of-line)
(setq n (count-lines 1 (point)))
(while (= flag 0)
(setq n (1+ n))
(dln-core (line-beginning-position)
(line-end-position)
(format display-line-number-format n
))
(forward-line 1)
(if (or (>= (point) end)
(>= (point) (point-max))
(not (equal (point) (line-beginning-position))))
(setq flag 1)))))))
(defun dln-undisplay ()
(interactive)
(save-excursion
(save-restriction
(widen)
(let ((es (overlays-in 1 (1+ (point-max)))))
(mapc (lambda (e)
(if (eq (overlay-get e 'name) 'dln-core)
(delete-overlay e)))
es)))))
(defun dln-after-change-function (&optional start end length)
(dln-undisplay)
(dln-display))
(defun dln-window-scroll-function (&optional win pos)
(dln-undisplay)
(dln-display))
(defun dln-window-configuration-change-function (&optional win pos)
(dln-undisplay)
(dln-display))
(provide 'display-line-number)
;;; display-line-number.el ends here
;; Copyright (C) 2004 Free Software Foundation, Inc.
;; Author: ChunYe Wang
;; Keywords: tools
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; Installation:
;; put the display-line-number.el in your load-path
;; (require 'display-line-number)
;; M-x display-line-number-mode
;; M-x display-line-number-mode-on
;; M-x display-line-number-mode-off
;;; Code:
(defvar display-line-number-mode nil
"Non-nil if display-line-number-mode is active in the current buffer.")
(make-variable-buffer-local 'display-line-number-mode)
(defvar display-line-number-face 'font-lock-keyword-face)
(defvar global-display-line-number-mode nil
"Non-nil if display-line-number-mode is active in the all buffer.")
(defvar display-line-number-format "%5d "
"String suitable for `format' that will generate a line number string.
`format' will be called with this string and one other argument
which will be an integer, the line number.")
(defun display-line-number-mode (&optional arg)
"Toggle display-line-number-mode.
With prefix argument, turn display-line-number-mode on if argument is positive.
When display-line-number-mode is enabled, a line number will appear at the left
margin of each line."
(interactive "P")
(if (null arg) (setq arg 0)
(setq arg (prefix-numeric-value arg)))
(cond
((> arg 0) (setq display-line-number-mode t))
((= arg 0) (setq display-line-number-mode
(not display-line-number-mode)))
((< arg 0) (setq display-line-number-mode nil)))
(if display-line-number-mode
(display-line-number-mode-on)
(display-line-number-mode-off)))
(defun global-display-line-number-mode (&optional arg)
"Toggle display-line-number-mode.
With prefix argument, turn display-line-number-mode on if argument is positive.
When display-line-number-mode is enabled, a line number will appear at the left
margin of each line."
(interactive "P")
(if (null arg) (setq arg 0)
(setq arg (prefix-numeric-value arg)))
(cond
((> arg 0) (setq global-display-line-number-mode t))
((= arg 0) (setq global-display-line-number-mode
(not global-display-line-number-mode)))
((< arg 0) (setq global-display-line-number-mode nil)))
(if global-display-line-number-mode
(add-hook 'find-file-hooks
'display-line-number-mode-on)
(remove-hook 'find-file-hooks
'display-line-number-mode-on))
(message "global display line number mode is %s" (if global-display-line-number-mode "on" "off")))
;; (global-display-line-number-mode (if global-display-line-number-mode 1 0))
(defun display-line-number-mode-on()
(interactive)
(setq display-line-number-mode t)
(dln-undisplay)
(dln-display)
(make-local-variable 'after-change-functions)
(make-local-variable 'window-scroll-functions)
(make-local-variable 'window-configuration-change-hook)
(add-to-list 'after-change-functions
'dln-after-change-function)
(add-to-list 'window-configuration-change-hook
'dln-window-configuration-change-function)
(add-to-list 'window-scroll-functions
'dln-window-scroll-function))
(defun display-line-number-mode-off()
(interactive)
(dln-undisplay)
(setq after-change-functions (remq
'dln-after-change-function
after-change-functions))
(setq window-configuration-change-hook (remq
'dln-window-configuration-change-function
window-configuration-change-hook))
(setq window-scroll-functions (remq
'dln-window-scroll-function
window-scroll-functions)))
(defun dln-core (start end str)
(let ((e (make-overlay start end)))
(overlay-put e 'before-string (propertize str 'face display-line-number-face))
(overlay-put e 'name 'dln-core)))
(defun dln-display ( &optional arg)
(interactive "p")
;; (setq left-margin-width 5)
;; (set-window-margins (selected-window) 5 0)
(let ((line-number 1)
(start (window-start (selected-window)))
(end (window-end (selected-window) t))
(n 0)
(flag 0))
(save-excursion
(save-restriction
(widen)
(goto-char start)
(beginning-of-line)
(setq n (count-lines 1 (point)))
(while (= flag 0)
(setq n (1+ n))
(dln-core (line-beginning-position)
(line-end-position)
(format display-line-number-format n
))
(forward-line 1)
(if (or (>= (point) end)
(>= (point) (point-max))
(not (equal (point) (line-beginning-position))))
(setq flag 1)))))))
(defun dln-undisplay ()
(interactive)
(save-excursion
(save-restriction
(widen)
(let ((es (overlays-in 1 (1+ (point-max)))))
(mapc (lambda (e)
(if (eq (overlay-get e 'name) 'dln-core)
(delete-overlay e)))
es)))))
(defun dln-after-change-function (&optional start end length)
(dln-undisplay)
(dln-display))
(defun dln-window-scroll-function (&optional win pos)
(dln-undisplay)
(dln-display))
(defun dln-window-configuration-change-function (&optional win pos)
(dln-undisplay)
(dln-display))
(provide 'display-line-number)
;;; display-line-number.el ends here
相关文章推荐
- 【VC插件】VC显示行号_VC6LineNumberAddin
- VC6.0显示行号插件:VC6LineNumberAddin.dll
- VC显示行号插件VC6LineNumberAddin
- VC++6.0 显示行号插件VC6LineNumberAddin.dll,破解版支持win7 64位系统
- VC++6显示行号插件+VC6LineNumberAddin.dll+注册机
- 用display: inline-block并排显示会多出空白
- 浅析Easyui Datagrid的Rownumber行号显示
- IO流_自定义类模拟LineNumberReader的获取行号功能案例
- Xcode中显示Line Numbers行号
- Easyui Datagrid的Rownumber行号显示问题
- Eclipes:设置显示代码行号Show line mumber
- html使用display:inline-block实现标签右对齐,值左对齐效果。和设置div宽度,并居中显示。嵌套div的里层div文字居中显示
- ubuntu16.04下Emacs 显示行号和更改背景颜色
- Emacs-124-像Source Insight一样显示行号
- Emacs显示行号
- 在Emacs显示行号
- C# 5.0 CallerMemberName CallerFilePath CallerLineNumber获取调用方法名称,路径,行号
- emacs显示行号
- 实现三个div同一行显示,IE6 and Ie7 :display:inline-block
- Easyui Datagrid的Rownumber行号显示问题