help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

what-char


From: Emanuel Berg
Subject: what-char
Date: Sat, 05 Feb 2022 09:13:39 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

New interesting code from uXu!

Have the echo area display the name and old-name (if
available) of the char at point.

Watch out for the argument pos! From Lisp, it means
position. Interactively, it means don't just echo, also kill
the data. But even from Lisp it can be omitted, and point
is used ...

If used interactively, the point number is also echoed, but
not returned or killed.

Tricky? Have no fear - "I" is here.

;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/char.el

(defun what-char (&optional pos)
  (interactive "P")
  (let*((position (or (and (numberp pos) pos)
                      (point) ))
        (kill pos)
        (char (char-after position)) )
    (when char
      (let*((name     (get-char-code-property char 'name))
            (old-name (get-char-code-property char 'old-name))
            (msg (if (and name old-name)
                     (format "%s (%s)" name old-name)
                   (or name old-name) ))
            (msg-dc (when (stringp msg) (downcase msg))) )
        (when msg-dc
          (prog1 msg-dc
            (when kill (kill-new msg-dc))
            (message "%d: %s" position msg-dc) ))))))

;; (what-char)                     ; "space"
;; (what-char (point-min))         ; "semicolon"
;; (what-char 692)                 ; "left parenthesis (opening parenthesis)"
;; C-u M-x what-char RET* then C-y ; asterisk is inserted
;; M-x what-char RET               ; 1016: line feed (lf)

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]