all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: <brianjiang@gdnt.com.cn>
To: <drew.adams@oracle.com>,
	<"mike|s/\\x40/\\./g; s/|.*|/\\x40/g;|trausch"@us.oracle.com>,
	<help-gnu-emacs@gnu.org>
Subject: RE: Does emacs have a line numbering feature?
Date: Mon, 10 Sep 2007 11:11:37 +0800	[thread overview]
Message-ID: <63F95800EDD046419F17688AAFD41CCF01D964A8@rnd-ex01.rnd.gdnt.local> (raw)
In-Reply-To: <DNEMKBNJBGPAOPIJOOICOEKBDPAA.drew.adams@oracle.com>

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.....................
      
      (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=gdnt.com.cn@gnu.org [mailto:help-gnu-emacs-bounces+brianjiang=gdnt.com.cn@gnu.org] On Behalf Of Drew Adams
Sent: 2007年9月10日 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 
> >> something similar for linum-mode, it seems to just ignore it.
> >
> > Yes, because setting a minor mode variable to activate it is the 
> > wrong thing to do.  It might work sometimes, but generally you 
> > should either customize the variable or use the minor mode function.  
> > 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 
> > positive.
> >
>
> Okay... I tried that, too, for linum-mode, and it doesn't work.  Am I 
> 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

  reply	other threads:[~2007-09-10  3:11 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.456.1189180395.18990.help-gnu-emacs@gnu.org>
2007-09-09  7:24 ` Does emacs have a line numbering feature? Unknown
2007-09-09 11:06   ` saint
     [not found]   ` <mailman.561.1189336001.18990.help-gnu-emacs@gnu.org>
2007-09-09 16:09     ` Unknown
2007-09-09 20:14       ` Tassilo Horn
2007-09-09 22:00         ` Unknown
2007-09-09 22:58           ` Drew Adams
2007-09-10  3:11             ` brianjiang [this message]
     [not found] <mailman.454.1189179783.18990.help-gnu-emacs@gnu.org>
2007-09-07 20:44 ` Tassilo Horn
2007-09-12  8:56 ` Andrew Russell
     [not found] <mailman.608.1189394026.18990.help-gnu-emacs@gnu.org>
2007-09-10  4:24 ` Markus Triska
     [not found] <mailman.597.1189378773.18990.help-gnu-emacs@gnu.org>
2007-09-09 23:31 ` Unknown
2007-09-10  1:41   ` David Kastrup
2007-09-07 15:42 arguellodw
2007-09-07 15:51 ` Drew Adams
2007-09-08  7:46   ` brianjiang
2007-09-08 14:37     ` Drew Adams
2007-09-08 15:53       ` brianjiang
2007-09-08 20:42         ` Drew Adams
2007-09-07 16:02 ` Michaël Cadilhac

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=63F95800EDD046419F17688AAFD41CCF01D964A8@rnd-ex01.rnd.gdnt.local \
    --to=brianjiang@gdnt.com.cn \
    --cc="mike|s/\\x40/\\./g; s/|.*|/\\x40/g;|trausch"@us.oracle.com \
    --cc=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.