emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: orgmode <emacs-orgmode@gnu.org>
Subject: [tip/offtopic] A function to describe the characters of a word at point
Date: Wed, 13 Jul 2022 10:49:48 +0000	[thread overview]
Message-ID: <87y1wxwalv.fsf@posteo.net> (raw)

Sorry for the slight offtopic.

Since Unicode and character issues come up here from time to time, I'm
sharing this 'homemade' function that I wrote a long time ago for my
work, in case someone finds it useful. It Shows a brief descriptive list
of all characters in a word at point. Each character includes the
Unicode name, code, and canonical decomposition. Example:

ἄρχοντα >>

ἄ (#1f04) ... GREEK SMALL LETTER ALPHA WITH PSILI AND OXIA ... descomp: #1f00 #301
ρ (#3c1) ... GREEK SMALL LETTER RHO ... descomp: #3c1
χ (#3c7) ... GREEK SMALL LETTER CHI ... descomp: #3c7
ο (#3bf) ... GREEK SMALL LETTER OMICRON ... descomp: #3bf
ν (#3bd) ... GREEK SMALL LETTER NU ... descomp: #3bd
τ (#3c4) ... GREEK SMALL LETTER TAU ... descomp: #3c4
α (#3b1) ... GREEK SMALL LETTER ALPHA ... descomp: #3b1


#+begin_src emacs-lisp
  (defun describe-chars-word-at-point ()
    (interactive)
    (setq chars-in-word nil)
    (if
        (not (current-word t t))
        (error "Not in a word at point...")
      (let
          ((word (current-word t t)))
        (save-excursion
          (with-temp-buffer
            (insert word)
            (goto-char (point-min))
            (while (re-search-forward "\\(.\\)" nil t)
              (let* ((char-name (save-excursion
                                  (backward-char)
                                  (get-char-code-property (char-after (point)) 'name)))
                     (char-desc (save-excursion
                                  (backward-char)
                                  (get-char-code-property (char-after (point)) 'decomposition)))
                     (char-format (concat (match-string 1) "\s" "("
                                          (format "#%x" (string-to-char (match-string 1)))
                                          ")\s...\s" char-name "\s...\sdecomp:\s"
                                          (mapconcat (lambda (cod)
                                                       (format "#%x" cod))
                                                     char-desc " "))))
                (push char-format chars-in-word)))
            (when (get-buffer "*chars in word*")
              (kill-buffer "*chars in word*"))
            (get-buffer-create "*chars in word*")
            (set-buffer "*chars in word*")
            (insert (mapconcat 'identity
                               (reverse chars-in-word) "\n"))
            (view-mode)
            (temp-buffer-window-show "*chars in word*"
                                     '((display-buffer-below-selected display-buffer-at-bottom)
                                       (inhibit-same-window . t)
                                       (window-height . fit-window-to-buffer))))
          (pop-to-buffer "*chars in word*")))))
#+end_src


             reply	other threads:[~2022-07-13 10:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-13 10:49 Juan Manuel Macías [this message]
2022-07-14 15:42 ` [tip/offtopic] A function to describe the characters of a word at point Marcin Borkowski
2022-07-14 22:30   ` Samuel Wales
2022-07-15  0:56   ` Juan Manuel Macías

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

  List information: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to=87y1wxwalv.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).