all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* what-cursor-position shows line-number
@ 2007-04-10  6:41 Andreas Roehler
  2007-04-10 18:48 ` Eli Zaretskii
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Roehler @ 2007-04-10  6:41 UTC (permalink / raw)
  To: help-gnu-emacs

for discussion:

The following patch lets `what-cursor-position' include the line-number.

Complete function below.

diff -c

*** /home/speck/emacs/lisp/simple.el    Wed Apr  4 09:34:02 2007
--- simple-ar.el    Tue Apr 10 08:25:38 2007
***************
*** 916,928 ****
    "Print info on cursor position (on screen and within buffer).
  Also describe the character after point, and give its character code
  in octal, decimal and hex.
-
  For a non-ASCII multibyte character, also give its encoding in the
  buffer's selected coding system if the coding system encodes the
  character safely.  If the character is encoded into one byte, that
  code is shown in hex.  If the character is encoded into more than one
  byte, just \"...\" is shown.
-
  In addition, with prefix argument, show details about that character
  in *Help* buffer.  See also the command `describe-char'."
    (interactive "P")
--- 916,926 ----
***************
*** 930,935 ****
--- 928,936 ----
       (beg (point-min))
       (end (point-max))
           (pos (point))
+      ;; 2007-04-10 a.roehler@web.de changed section start
+      (line (line-number-at-pos))
+      ;; 2007-04-10 a.roehler@web.de changed section end
       (total (buffer-size))
       (percent (if (> total 50000)
                ;; Avoid overflow from multiplying by 100!
***************
*** 991,1003 ****
               (single-key-description char)
                 (buffer-substring-no-properties (point) (1+ (point))))
               encoding-msg pos total percent beg end col hscroll)
!       (message "Char: %s %s point=%d of %d (%d%%) column=%d%s"
             (if enable-multibyte-characters
                 (if (< char 128)
                 (single-key-description char)
               (buffer-substring-no-properties (point) (1+ (point))))
               (single-key-description char))
!            encoding-msg pos total percent col hscroll))))))
 
  ;; Initialize read-expression-map.  It is defined at C level.
  (let ((m (make-sparse-keymap)))
--- 992,1008 ----
               (single-key-description char)
                 (buffer-substring-no-properties (point) (1+ (point))))
               encoding-msg pos total percent beg end col hscroll)
!       ;; 2007-04-10 a.roehler@web.de changed section start    
!       (message "Char: %s %s point=%d of %d (%d%%) column=%d%s line=%d"
!            ;; 2007-04-10 a.roehler@web.de changed section end
             (if enable-multibyte-characters
                 (if (< char 128)
                 (single-key-description char)
               (buffer-substring-no-properties (point) (1+ (point))))
               (single-key-description char))
!            ;; 2007-04-10 a.roehler@web.de changed section start
!            encoding-msg pos total percent col hscroll line))))))
!
 
  ;; Initialize read-expression-map.  It is defined at C level.
  (let ((m (make-sparse-keymap)))

;;;;;;;;;;;;;;


(defun what-cursor-position (&optional detail)
  "Print info on cursor position (on screen and within buffer).
Also describe the character after point, and give its character code
in octal, decimal and hex.
For a non-ASCII multibyte character, also give its encoding in the
buffer's selected coding system if the coding system encodes the
character safely.  If the character is encoded into one byte, that
code is shown in hex.  If the character is encoded into more than one
byte, just \"...\" is shown.
In addition, with prefix argument, show details about that character
in *Help* buffer.  See also the command `describe-char'."
  (interactive "P")
  (let* ((char (following-char))
     (beg (point-min))
     (end (point-max))
         (pos (point))
     ;; 2007-04-10 a.roehler@web.de changed section start
     (line (line-number-at-pos))
     ;; 2007-04-10 a.roehler@web.de changed section end
     (total (buffer-size))
     (percent (if (> total 50000)
              ;; Avoid overflow from multiplying by 100!
              (/ (+ (/ total 200) (1- pos)) (max (/ total 100) 1))
            (/ (+ (/ total 2) (* 100 (1- pos))) (max total 1))))
     (hscroll (if (= (window-hscroll) 0)
              ""
            (format " Hscroll=%d" (window-hscroll))))
     (col (current-column)))
    (if (= pos end)
    (if (or (/= beg 1) (/= end (1+ total)))
        (message "point=%d of %d (%d%%) <%d-%d> column=%d%s"
             pos total percent beg end col hscroll)
      (message "point=%d of %d (EOB) column=%d%s"
           pos total col hscroll))
      (let ((coding buffer-file-coding-system)
        encoded encoding-msg display-prop under-display)
    (if (or (not coding)
        (eq (coding-system-type coding) t))
        (setq coding default-buffer-file-coding-system))
    (if (not (char-valid-p char))
        (setq encoding-msg
          (format "(%d, #o%o, #x%x, invalid)" char char char))
      ;; Check if the character is displayed with some `display'
      ;; text property.  In that case, set under-display to the
      ;; buffer substring covered by that property.
      (setq display-prop (get-text-property pos 'display))
      (if display-prop
          (let ((to (or (next-single-property-change pos 'display)
                (point-max))))
        (if (< to (+ pos 4))
            (setq under-display "")
          (setq under-display "..."
            to (+ pos 4)))
        (setq under-display
              (concat (buffer-substring-no-properties pos to)
                  under-display)))
        (setq encoded (and (>= char 128) (encode-coding-char char coding))))
      (setq encoding-msg
        (if display-prop
            (if (not (stringp display-prop))
            (format "(%d, #o%o, #x%x, part of display \"%s\")"
                char char char under-display)
              (format "(%d, #o%o, #x%x, part of display \"%s\"->\"%s\")"
                  char char char under-display display-prop))
          (if encoded
              (format "(%d, #o%o, #x%x, file %s)"
                  char char char
                  (if (> (length encoded) 1)
                  "..."
                (encoded-string-description encoded coding)))
            (format "(%d, #o%o, #x%x)" char char char)))))
    (if detail
        ;; We show the detailed information about CHAR.
        (describe-char (point)))
    (if (or (/= beg 1) (/= end (1+ total)))
        (message "Char: %s %s point=%d of %d (%d%%) <%d-%d> column=%d%s"
             (if (< char 256)
             (single-key-description char)
               (buffer-substring-no-properties (point) (1+ (point))))
             encoding-msg pos total percent beg end col hscroll)
      ;; 2007-04-10 a.roehler@web.de changed section start    
      (message "Char: %s %s point=%d of %d (%d%%) column=%d%s line=%d"
           ;; 2007-04-10 a.roehler@web.de changed section end
           (if enable-multibyte-characters
               (if (< char 128)
               (single-key-description char)
             (buffer-substring-no-properties (point) (1+ (point))))
             (single-key-description char))
           ;; 2007-04-10 a.roehler@web.de changed section start
           encoding-msg pos total percent col hscroll line))))))

;;; End

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: what-cursor-position shows line-number
  2007-04-10  6:41 what-cursor-position shows line-number Andreas Roehler
@ 2007-04-10 18:48 ` Eli Zaretskii
  2007-04-10 19:39   ` Andreas Roehler
  0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2007-04-10 18:48 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Tue, 10 Apr 2007 08:41:34 +0200
> From: Andreas Roehler <andreas.roehler@easy-emacs.de>
> 
> The following patch lets `what-cursor-position' include the line-number.

Since the line number is by default displayed in the mode line, I
wonder what would be the importance of having it repeated by C-x =.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: what-cursor-position shows line-number
  2007-04-10 18:48 ` Eli Zaretskii
@ 2007-04-10 19:39   ` Andreas Roehler
  0 siblings, 0 replies; 3+ messages in thread
From: Andreas Roehler @ 2007-04-10 19:39 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

Eli Zaretskii schrieb:
>> Date: Tue, 10 Apr 2007 08:41:34 +0200
>> From: Andreas Roehler <andreas.roehler@easy-emacs.de>
>>
>> The following patch lets `what-cursor-position' include the line-number.
>
> Since the line number is by default displayed in the mode line, I
> wonder what would be the importance of having it repeated by C-x =.
>
Needed space in mode-line for `which-function-mode'

Beside percentage shown there isn't longer useful with scroll
bars.

So I abolished both.

At the other hand:  it's enough space in message-buffer when
`what-cursor-position' is called, can't see a harm.

For example

Char: C-j (10, #o12, #xa) point=238 of 238 (100%) column=0 line=11

looks consistent.



Andreas Roehler

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-04-10 19:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-04-10  6:41 what-cursor-position shows line-number Andreas Roehler
2007-04-10 18:48 ` Eli Zaretskii
2007-04-10 19:39   ` Andreas Roehler

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.