Mercurial > hg > xemacs-beta
comparison lisp/packages/column.el @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | b82b59fe008d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
1 ;;; column.el --- display line and column in the mode line | |
2 | |
3 ;; Copyright (C) 1993 Per Abrahamsen. | |
4 ;; Copyright abandoned. This file is donated to the public domain. | |
5 | |
6 ;; Author: Per Abrahamsen <abraham@iesd.auc.dk> | |
7 ;; Hacked for XEmacs by Richard Lee <rlee@vienna.itd.sterling.com> | |
8 ;; Version: 0.2 | |
9 ;; Bogus-Bureaucratic-Cruft: How 'bout ESR and the LCD people agreed | |
10 ;; on a common format? | |
11 | |
12 ;;; Synched up with: Not in FSF. | |
13 | |
14 ;;; Commentary: | |
15 | |
16 ;; LCD Archive Entry: | |
17 ;; column|Per Abrahamsen|abraham@iesd.auc.dk| | |
18 ;; Display line and column in the mode line| | |
19 ;; 1993-12-31|0.2|~/misc/column.el.Z| | |
20 | |
21 ;; Requires FSF Emacs 19. ***** or Lucid Emacs 19.6+ -- Richard Lee | |
22 | |
23 ;;; Change Log: | |
24 ;; | |
25 ;; Tue Jan 04 19:51:15 1994 Richard Lee ***** | |
26 ;; * Hacks for Lemacs: | |
27 ;; changed display-column-after from ")%--" to ")%----" | |
28 ;; defined current-line (function and variable) | |
29 ;; changed display-column-format to use current-line instead of %l | |
30 ;; Fri Dec 31 13:46:41 1993 | |
31 ;; * Change mode-line-format directly instead of using a minor mode. | |
32 ;; Thu Dec 16 14:57:15 1993 | |
33 ;; * Removed (require 'lucid) as unnecessary. | |
34 ;; Fri Aug 13 02:06:18 1993 Per Abrahamsen | |
35 ;; * Made current-column buffer local. | |
36 ;; Tue Aug 10 10:00:00 1993 Per Abrahamsen | |
37 ;; * Created. | |
38 | |
39 ;; This version should display column and line number the same place as | |
40 ;; line-number-mode. Activate with | |
41 | |
42 ;; M-x display-column-mode RET | |
43 | |
44 ;; For FSF Emacs 19 only. You can get line+.el or linenumber.el from the | |
45 ;; emacs lisp archive if you have another version of Emacs. Not tested. | |
46 | |
47 ;;; Code: | |
48 | |
49 ;; String containing current column as last evaluated. | |
50 (defvar current-column "0") | |
51 (defvar current-line "0") | |
52 (make-variable-buffer-local 'current-column) | |
53 (make-variable-buffer-local 'current-line) | |
54 | |
55 ;; Returns the vertical position of point _relative to beginning of buffer_ | |
56 ;; (as opposed to the current-line example in the gnu-emacs 19 info page on | |
57 ;; Text Lines, which does it relative to top of screen.) ***** -- Richard Lee | |
58 ;; ben: lines begin at 1, not 0! | |
59 (defun current-line () | |
60 "Return the vertical position of point in the selected window. | |
61 First line in the buffer is 1." | |
62 (1+ (+ (count-lines 1 (point)) | |
63 (if (= (current-column) 0) 1 0) | |
64 -1))) | |
65 | |
66 ;; Function updating the string containing the current column. | |
67 (defvar update-column-function | |
68 (function (lambda () | |
69 (setq current-column (int-to-string (current-column))) | |
70 (setq current-line (int-to-string (current-line))) | |
71 (set-buffer-modified-p (buffer-modified-p))))) | |
72 | |
73 (defvar display-column-mode nil | |
74 "Show current column and line in mode line if non-nil.") | |
75 | |
76 (defvar display-column-format '(current-line "/" current-column "--") | |
77 "Format for displaying the line and column in the mode line.") | |
78 | |
79 ;; Entry for column mode in mode line. | |
80 (defconst display-column-entry | |
81 (list 'display-column-mode (cons "" display-column-format))) | |
82 | |
83 (defvar display-column-after ")%]----" | |
84 "Display column after this element in the mode line.") | |
85 | |
86 ;; Add display-column-format to mode-line-format after display-column-after. | |
87 (or (member display-column-entry mode-line-format) | |
88 (let ((entry (member display-column-after mode-line-format))) | |
89 (setcdr entry (cons display-column-entry (cdr entry))))) | |
90 | |
91 (defun remove (it list) | |
92 (cond ((null list) nil) | |
93 ((eq it (car list)) (cdr list)) | |
94 (t (setcdr list (remove it (cdr list))) list))) | |
95 | |
96 ;;;###autoload | |
97 (defun display-column-mode (&optional arg) | |
98 "Toggle display column mode. | |
99 With prefix arg, turn display column mode on iff arg is positive. | |
100 | |
101 When display column mode is on, the current column and line number are | |
102 displayed in the mode line." | |
103 (interactive "P") | |
104 (if (or (and (null arg) display-column-mode) | |
105 (<= (prefix-numeric-value arg) 0)) | |
106 ;; Turn it off | |
107 (if display-column-mode | |
108 (progn | |
109 (remove-hook 'post-command-hook update-column-function) | |
110 (setq display-column-mode nil) | |
111 (set-buffer-modified-p (buffer-modified-p)))) | |
112 ;;Turn it on | |
113 (if display-column-mode | |
114 () | |
115 (add-hook 'post-command-hook update-column-function) | |
116 (setq display-column-mode t)))) | |
117 | |
118 (provide 'column) | |
119 | |
120 ;;; column.el ends here |