From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: RE: Does emacs have a line numbering feature? Date: Mon, 10 Sep 2007 11:11:37 +0800 Message-ID: <63F95800EDD046419F17688AAFD41CCF01D964A8@rnd-ex01.rnd.gdnt.local> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1189395892 27149 80.91.229.12 (10 Sep 2007 03:44:52 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 10 Sep 2007 03:44:52 +0000 (UTC) To: , <"mike|s/\\x40/\\./g; s/|.*|/\\x40/g;|trausch"@us.oracle.com>, Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Sep 10 13:44:38 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IUhDE-0001mY-C0 for geh-help-gnu-emacs@m.gmane.org; Mon, 10 Sep 2007 13:13:52 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IUZir-0006VL-SP for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Sep 2007 23:14:01 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IUZia-0006V5-JN for help-gnu-emacs@gnu.org; Sun, 09 Sep 2007 23:13:44 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IUZiY-0006Ty-SD for help-gnu-emacs@gnu.org; Sun, 09 Sep 2007 23:13:43 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IUZiY-0006Tt-Kz for help-gnu-emacs@gnu.org; Sun, 09 Sep 2007 23:13:42 -0400 Original-Received: from email.gdnt.com.cn ([202.104.30.38]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IUZiX-0000Vk-Gc for help-gnu-emacs@gnu.org; Sun, 09 Sep 2007 23:13:42 -0400 Original-Received: from sd-ef-01.cnshn.gdnt.local ([202.38.41.132]) by email.gdnt.com.cn with Microsoft SMTPSVC(6.0.3790.1830); Mon, 10 Sep 2007 11:15:33 +0800 Original-Received: from sd-ex-01.cnshn.gdnt.local ([202.38.38.8]) by sd-ef-01.cnshn.gdnt.local with Microsoft SMTPSVC(6.0.3790.1830); Sun, 9 Sep 2007 22:15:47 -0500 Original-Received: from rnd-ex01.rnd.gdnt.local ([202.38.32.250]) by sd-ex-01.cnshn.gdnt.local with Microsoft SMTPSVC(6.0.3790.1830); Mon, 10 Sep 2007 11:15:47 +0800 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message In-Reply-To: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Does emacs have a line numbering feature? Thread-Index: AcfzNZR6lN7eIT/5RoOZtJ0g0nO+XAAH96lA X-OriginalArrivalTime: 10 Sep 2007 03:15:47.0333 (UTC) FILETIME=[E1BDC350:01C7F358] X-TM-AS-Product-Ver: SMEX-7.0.0.1345-3.6.1039-15232.002 X-TM-AS-Result: No--27.099400-8.000000-31 X-Detected-Kernel: Windows 2000 SP4, XP SP1+ X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:47424 Archived-At: I find sometimes the line number doesn't show. e.g., open a file, then = use "occur" to find a text string and click occur buffer to jump to the = next occurrence of string in another page, then the line number doesn't = show. When I click the file buffer, the line numbers then show. I find it is because the linum.el uses "window-start" and "window-end" = to determine the which text lines are visible currently. But they are = sometimes not reliable. See the text from the "help": Redisplay updates the window-start position (if you have not specified it explicitly since the previous redisplay)--for example, to make sure point appears on the screen. Nothing except redisplay automatically changes the window-start position; if you move point, do not expect the window-start position to change in response until after the next redisplay. So I change something in the linum.el as below. And it currently works = well for me. Maybe there are some better solutions I don't know. (defun linum-update () "Update displayed line numbers for the current buffer." (save-excursion ;;(goto-char (window-start)) ;; brian: comment out (let (;;(line (line-number-at-pos)) ;; brian ;;(limit (1+ (window-end nil t))) ;; brian line limit pos w-h w-s (fmt (if (stringp linum-format) linum-format = (linum-dynamic-format))) ov free) ;; brian: hack it........................... (setq pos (point)) (setq w-s (window-start)) (setq limit (1+ (window-end nil t)) ) (when (or (> pos limit) (< pos w-s)) (setq w-h (window-height)) (forward-line w-h) (setq limit (point)) ;; don't worry about nagitive position (goto-char pos) (forward-line (- 0 w-h)) (setq w-s (point)) ) (goto-char w-s) (setq line (line-number-at-pos)) ;; brian: end of hacking..................... =20 (dolist (ov (overlays-in (point) limit)) (when (overlay-get ov 'linum) (push ov free))) ;; Create an overlay (or reuse an existing one) for each visible ;; line in this window. (while (and (not (eobp)) (< (point) limit)) (if (null free) (progn (setq ov (make-overlay (point) (point))) (overlay-put ov 'linum t) (push ov linum-overlays)) (setq ov (pop free)) (move-overlay ov (point) (point))) (overlay-put ov 'before-string (format fmt line)) (overlay-put ov 'margin 'left-margin) (forward-line) (setq line (1+ line))) (mapc #'delete-overlay free)))) Regards, Brian -----Original Message----- From: help-gnu-emacs-bounces+brianjiang=3Dgdnt.com.cn@gnu.org = [mailto:help-gnu-emacs-bounces+brianjiang=3Dgdnt.com.cn@gnu.org] On = Behalf Of Drew Adams Sent: 2007=C4=EA9=D4=C210=C8=D5 6:59 To: Michael Trausch; help-gnu-emacs@gnu.org Subject: RE: Does emacs have a line numbering feature? > >>> (setq line-number-mode t) > >>> (setq column-number-mode t) > >> Yeah, I already had that in, and it works. However, if I do=20 > >> something similar for linum-mode, it seems to just ignore it. > > > > Yes, because setting a minor mode variable to activate it is the=20 > > wrong thing to do. It might work sometimes, but generally you=20 > > should either customize the variable or use the minor mode function. = =20 > > So the code above should better be > > > > (line-number-mode 1) > > (column-number-mode 1) > > > > because by convention a minor mode is turned on if the argument is=20 > > positive. > > > > Okay... I tried that, too, for linum-mode, and it doesn't work. Am I=20 > missing something obvious or am I an idiot? :-P Linum mode is a local minor mode: turning it on does so only for the = current buffer. Are you using Emacs 22? If so, then you can define a different command, = `global-linum-mode', as follows (after loading linum.el): (define-globalized-minor-mode global-linum-mode linum-mode (lambda nil (linum-mode 1))) Then just put this in your .emacs: (global-linum-mode 1). You can toggle line numbering in all buffers at once using command = `global-linum-mode'. Even the minibuffer is affected, which might not be = what you want. You might ask Markus to add this command to the library. If you don't have Emacs 22, then you will probably need to turn on the (local) mode in each buffer, using a hook. HTH. _______________________________________________ help-gnu-emacs mailing list help-gnu-emacs@gnu.org http://lists.gnu.org/mailman/listinfo/help-gnu-emacs