0
|
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
|
4
|
68 (lambda ()
|
|
69 (setq current-column
|
|
70 (int-to-string (if (and (boundp 'column-number-start-at-one)
|
|
71 column-number-start-at-one)
|
|
72 (1+ (current-column))
|
|
73 (current-column))))
|
|
74 (setq current-line (int-to-string (current-line)))
|
|
75 (set-buffer-modified-p (buffer-modified-p))))
|
0
|
76
|
|
77 (defvar display-column-mode nil
|
|
78 "Show current column and line in mode line if non-nil.")
|
|
79
|
|
80 (defvar display-column-format '(current-line "/" current-column "--")
|
|
81 "Format for displaying the line and column in the mode line.")
|
|
82
|
|
83 ;; Entry for column mode in mode line.
|
|
84 (defconst display-column-entry
|
|
85 (list 'display-column-mode (cons "" display-column-format)))
|
|
86
|
|
87 (defvar display-column-after ")%]----"
|
|
88 "Display column after this element in the mode line.")
|
|
89
|
|
90 ;; Add display-column-format to mode-line-format after display-column-after.
|
|
91 (or (member display-column-entry mode-line-format)
|
|
92 (let ((entry (member display-column-after mode-line-format)))
|
|
93 (setcdr entry (cons display-column-entry (cdr entry)))))
|
|
94
|
|
95 (defun remove (it list)
|
|
96 (cond ((null list) nil)
|
|
97 ((eq it (car list)) (cdr list))
|
|
98 (t (setcdr list (remove it (cdr list))) list)))
|
|
99
|
|
100 ;;;###autoload
|
|
101 (defun display-column-mode (&optional arg)
|
|
102 "Toggle display column mode.
|
|
103 With prefix arg, turn display column mode on iff arg is positive.
|
|
104
|
|
105 When display column mode is on, the current column and line number are
|
|
106 displayed in the mode line."
|
|
107 (interactive "P")
|
|
108 (if (or (and (null arg) display-column-mode)
|
|
109 (<= (prefix-numeric-value arg) 0))
|
|
110 ;; Turn it off
|
|
111 (if display-column-mode
|
|
112 (progn
|
|
113 (remove-hook 'post-command-hook update-column-function)
|
|
114 (setq display-column-mode nil)
|
|
115 (set-buffer-modified-p (buffer-modified-p))))
|
|
116 ;;Turn it on
|
|
117 (if display-column-mode
|
|
118 ()
|
|
119 (add-hook 'post-command-hook update-column-function)
|
|
120 (setq display-column-mode t))))
|
|
121
|
|
122 (provide 'column)
|
|
123
|
|
124 ;;; column.el ends here
|