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