[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
ccl.el --- Display total lines/columns in modeline.
From: |
Zajcev Evgeny |
Subject: |
ccl.el --- Display total lines/columns in modeline. |
Date: |
Mon, 15 Nov 2004 21:19:30 +0300 |
User-agent: |
Gnus/5.1002 (Gnus v5.10.2) XEmacs/21.4 (Security Through Obscurity, berkeley-unix) |
This code works on XEmacs with line-number-mode/column-number-mode
enabled in modeline. I'm not sure it will work on GNU Emacs.
----- Cut here ----
;;; ccl.el --- Count columns and lines minor mode.
;; Copyright (C) 2004 by Free Software Foundation, Inc.
;; Author: Zajcev Evgeny <address@hidden>
;; Created: Sun Nov 14 02:34:07 MSK 2004
;; Keywords: utils
;; X-CVS: $Id$
;; This file is NOT part of XEmacs.
;; XEmacs 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.
;; XEmacs 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 XEmacs; see the file COPYING. If not, write to the Free
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
;; 02111-1307, USA.
;;; Synched up with: Not in FSF
;;; Commentary:
;; Show information about total number of lines and nuber of columns
;; for line at point in modeline. To turn it on use:
;; M-x ccl-turn-on-mode RET
;; ccl mode does not strike performance. Simple profiling
;; `ccl-update-lines' and `ccl-update-columns' functions gives next
;; result:
;; On big files (lines: ~1500)
;; Function Name Call Count Elapsed Time Average Time
;; ================== ========== ============ ============
;; ccl-update-lines 1086 0.8463739999 0.0007793499
;; ccl-update-columns 1086 0.0369940000 3.406...e-05
;; On typical files (lines: < 500)
;; Function Name Call Count Elapsed Time Average Time
;; ================== ========== ============ ============
;; ccl-update-lines 1273 0.0640020000 5.027...e-05
;; ccl-update-columns 1273 0.0432100000 3.394...e-05
;;; Note:
;; ccl does not provide way to turn it off. joke. Use:
;; M-x ccl-turn-off-mode RET
;; But I'm sure you will not ever use it.
;;; Code:
(defcustom ccl-minor-mode nil
"*Non-nil mean ccl minor mode is enabled."
:type 'boolean
:set 'ccl-set-minor-mode
:initialize 'custom-initialize-default)
(defvar ccl-total-lines "")
(make-variable-buffer-local 'ccl-total-lines)
(defvar ccl-total-columns "")
(make-variable-buffer-local 'ccl-total-columns)
(defun ccl-update-lines ()
"Update `ccl-total-lines' value."
(setq ccl-total-lines
(concat "/"
(int-to-string (1+ (count-lines (point-min) (point-max)))))))
(defun ccl-update-columns ()
"Update `ccl-total-columns' value."
(setq ccl-total-columns
(concat "/" (int-to-string (- (point-at-eol) (point-at-bol))))))
;;;###autoload
(defun ccl-turn-on-mode ()
"Enable ccl minor mode for current buffer."
(interactive)
(add-hook 'post-command-hook 'ccl-update-lines)
(add-hook 'post-command-hook 'ccl-update-columns)
(setq ccl-minor-mode t)
(ccl-update-modeline-format))
(defun ccl-turn-off-mode ()
"Disable ccl minor mode for current buffer."
(interactive)
(setq ccl-minor-mode nil)
(remove-hook 'post-command-hook 'ccl-update-lines)
(remove-hook 'post-command-hook 'ccl-update-columns))
;;;###autoload
(defun ccl-set-minor-mode (svar sval)
"Set function for `ccl-minor-mode'.
SVAR is not used.
If SVAL is non-nil then enable `ccl-minor-mode', otherwise disable it."
(funcall (if sval 'ccl-turn-on-mode 'ccl-turn-off-mode)))
(defun ccl-update-modeline-format ()
"Update `modeline-format' to show ccl info."
(unless (get 'ccl 'updated-p)
(let ((ml modeline-format))
(while ml
(when (listp (car ml))
(cond ((eq (car (car ml)) 'line-number-mode)
(setcar ml '(line-number-mode "L%l"))
(setcdr ml (nconc '((ccl-minor-mode ccl-total-lines)
(line-number-mode "--"))
(cdr ml)))
(setq ml (cdr (cdr ml))))
((eq (car (car ml)) 'column-number-mode)
(setcar ml '(column-number-mode "C%c"))
(setcdr ml (nconc '((ccl-minor-mode ccl-total-columns)
(column-number-mode "--"))
(cdr ml)))
(setq ml (cdr (cdr ml))))))
(setq ml (cdr ml))))
(put 'ccl 'updated-p t)))
(provide 'ccl)
;;; ccl.el ends here
----- Cut ends here ----
--
lg
- ccl.el --- Display total lines/columns in modeline.,
Zajcev Evgeny <=