Function: what-cursor-position
what-cursor-position is an interactive and byte-compiled function
defined in simple.el.gz.
Signature
(what-cursor-position &optional DETAIL)
Documentation
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. If what-cursor-show-names is
non-nil, additionally show the name of the character.
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.
Probably introduced at or before Emacs version 27.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/simple.el.gz
(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. If `what-cursor-show-names' is
non-nil, additionally show the name of the character.
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))
(char-name (and what-cursor-show-names
(char-to-name char)))
(char-name-fmt (if char-name
(format ", %s" char-name)
""))
(bidi-fixer
;; If the character is one of LRE, LRO, RLE, RLO, it will
;; start a directional embedding, which could completely
;; disrupt the rest of the line (e.g., RLO will display the
;; rest of the line right-to-left). So we put an invisible
;; PDF character after these characters, to end the
;; embedding, which eliminates any effects on the rest of
;; the line. For RLE and RLO we also append an invisible
;; LRM, to avoid reordering the following numerical
;; characters. For LRI/RLI/FSI we append a PDI.
(cond ((memq char '(?\x202a ?\x202d))
(propertize (string ?\x202c) 'invisible t))
((memq char '(?\x202b ?\x202e))
(propertize (string ?\x202c ?\x200e) 'invisible t))
((memq char '(?\x2066 ?\x2067 ?\x2068))
(propertize (string ?\x2069) 'invisible t))
;; Strong right-to-left characters cause reordering of
;; the following numerical characters which show the
;; codepoint, so append LRM to countermand that.
((memq (get-char-code-property char 'bidi-class) '(R AL))
(propertize (string ?\x200e) 'invisible t))
(t
"")))
(beg (point-min))
(end (point-max))
(pos (point))
(total (buffer-size))
(percent (round (* 100.0 (1- pos)) (max 1 total)))
(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 (or (default-value 'buffer-file-coding-system)
;; A nil value of `buffer-file-coding-system'
;; means "no conversion" which means each byte
;; is a char and vice versa.
'binary)))
(if (eq (char-charset char) 'eight-bit)
(setq encoding-msg
(format "(%d, #o%o, #x%x%s, raw-byte)" char char char char-name-fmt))
;; 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-char-property pos 'display))
(if display-prop
(let ((to (or (next-single-char-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%s, part of display \"%s\")"
char char char char-name-fmt under-display)
(format "(%d, #o%o, #x%x%s, part of display \"%s\"->\"%s\")"
char char char char-name-fmt under-display display-prop))
(if encoded
(format "(%d, #o%o, #x%x%s, file %s)"
char char char char-name-fmt
(if (> (length encoded) 1)
"..."
(encoded-string-description encoded coding)))
(format "(%d, #o%o, #x%x%s)" char char char char-name-fmt)))))
(if detail
;; We show the detailed information about CHAR.
(describe-char (point)))
(if (or (/= beg 1) (/= end (1+ total)))
(message "Char: %s%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))))
bidi-fixer
encoding-msg pos total percent beg end col hscroll)
(message "Char: %s%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))
bidi-fixer encoding-msg pos total percent col hscroll))))))