all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andreas Roehler <andreas.roehler@easy-emacs.de>
To: help-gnu-emacs@gnu.org
Subject: what-cursor-position shows line-number
Date: Tue, 10 Apr 2007 08:41:34 +0200	[thread overview]
Message-ID: <461B319E.6090401@easy-emacs.de> (raw)

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

             reply	other threads:[~2007-04-10  6:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-10  6:41 Andreas Roehler [this message]
2007-04-10 18:48 ` what-cursor-position shows line-number Eli Zaretskii
2007-04-10 19:39   ` Andreas Roehler

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=461B319E.6090401@easy-emacs.de \
    --to=andreas.roehler@easy-emacs.de \
    --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.