home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / packages / column.el < prev    next >
Encoding:
Text File  |  1995-01-27  |  4.0 KB  |  120 lines

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