* [tip/offtopic] A function to describe the characters of a word at point
@ 2022-07-13 10:49 Juan Manuel Macías
2022-07-14 15:42 ` Marcin Borkowski
0 siblings, 1 reply; 4+ messages in thread
From: Juan Manuel Macías @ 2022-07-13 10:49 UTC (permalink / raw
To: orgmode
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [tip/offtopic] A function to describe the characters of a word at point
2022-07-13 10:49 [tip/offtopic] A function to describe the characters of a word at point Juan Manuel Macías
@ 2022-07-14 15:42 ` Marcin Borkowski
2022-07-14 22:30 ` Samuel Wales
2022-07-15 0:56 ` Juan Manuel Macías
0 siblings, 2 replies; 4+ messages in thread
From: Marcin Borkowski @ 2022-07-14 15:42 UTC (permalink / raw
To: Juan Manuel Macías; +Cc: orgmode
On 2022-07-13, at 12:49, Juan Manuel Macías <maciaschain@posteo.net> wrote:
> Sorry for the slight offtopic.
Not off-topic at all, as far as I'm concerned! (Though sending this to
help-gnu-emacs might be an even better idea.) I use `C-u C-x =' pretty
often, so I fully understand why someone might want to code something
like this. Very nice, thanks for sharing!
You might want to extend it and create a minor mode which would display
data about the current character in the echo area, Eldoc-style, or in
a tooltip when you hover the mouse pointer over a character. Depending
on what exactly you need, these ideas might be more or less useful, of
course.
Also, since the answer to quite a few org-related issues seems to be
"just insert a zero-width space", making those stand out (like
non-breaking spaces already are) could also be useful. FWIW, I have
this function in my init.el:
(defun insert-zero-width-space ()
"Insert Unicode character \"zero-width space\"."
(interactive)
(insert ""))
(of course, the 0-width space is invisible between the quotes).
Best,
mbork
> 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
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [tip/offtopic] A function to describe the characters of a word at point
2022-07-14 15:42 ` Marcin Borkowski
@ 2022-07-14 22:30 ` Samuel Wales
2022-07-15 0:56 ` Juan Manuel Macías
1 sibling, 0 replies; 4+ messages in thread
From: Samuel Wales @ 2022-07-14 22:30 UTC (permalink / raw
To: Marcin Borkowski; +Cc: Juan Manuel Macías, orgmode
good idea for command. i like the additional ideas too like the help
text [i hae that put in echo area even in gui].
for even more blue sky stuff, i was thinking along the lines of
information about characters, such as en/locale meanings for cjk. or
furigana [ruby text] for the echo area. requires lookup though. (to
go along with meanings for input method. :))
On 7/14/22, Marcin Borkowski <mbork@mbork.pl> wrote:
>
> On 2022-07-13, at 12:49, Juan Manuel Macías <maciaschain@posteo.net> wrote:
>
>> Sorry for the slight offtopic.
>
> Not off-topic at all, as far as I'm concerned! (Though sending this to
> help-gnu-emacs might be an even better idea.) I use `C-u C-x =' pretty
> often, so I fully understand why someone might want to code something
> like this. Very nice, thanks for sharing!
>
> You might want to extend it and create a minor mode which would display
> data about the current character in the echo area, Eldoc-style, or in
> a tooltip when you hover the mouse pointer over a character. Depending
> on what exactly you need, these ideas might be more or less useful, of
> course.
>
> Also, since the answer to quite a few org-related issues seems to be
> "just insert a zero-width space", making those stand out (like
> non-breaking spaces already are) could also be useful. FWIW, I have
> this function in my init.el:
>
> (defun insert-zero-width-space ()
> "Insert Unicode character \"zero-width space\"."
> (interactive)
> (insert ""))
>
> (of course, the 0-width space is invisible between the quotes).
>
> Best,
> mbork
>
>
>
>> 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
>
>
> --
> Marcin Borkowski
> http://mbork.pl
>
>
--
The Kafka Pandemic
A blog about science, health, human rights, and misopathy:
https://thekafkapandemic.blogspot.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [tip/offtopic] A function to describe the characters of a word at point
2022-07-14 15:42 ` Marcin Borkowski
2022-07-14 22:30 ` Samuel Wales
@ 2022-07-15 0:56 ` Juan Manuel Macías
1 sibling, 0 replies; 4+ messages in thread
From: Juan Manuel Macías @ 2022-07-15 0:56 UTC (permalink / raw
To: Marcin Borkowski; +Cc: Samuel Wales, orgmode
Hi, Marcin and Samuel, thanks for your comments,
Marcin Borkowski writes:
> You might want to extend it and create a minor mode which would display
> data about the current character in the echo area, Eldoc-style, or in
> a tooltip when you hover the mouse pointer over a character. Depending
> on what exactly you need, these ideas might be more or less useful, of
> course.
I also have written a smaller function to display a quick information of
a single character at point, something much simpler and not as verbose
as describe-char. But it had never occurred to me to do something
eldoc-like with it. In my case, although for those contexts I prefer
quick information (describe-char also has its relaxing moment), I don't
feel such an urgency :-).
In any case, something quick and dirty, just as a proof of concept,
could be this:
(define-minor-mode char-info-at-point-mode
"TODO"
:init-value nil
:lighter ("chinfo")
(if char-info-at-point-mode
(add-hook 'post-command-hook #'char-name-at-point nil t)
(remove-hook 'post-command-hook #'char-name-at-point 'local)))
(defun char-name-at-point ()
(interactive)
(let* ((char-name (get-char-code-property (char-after (point)) 'name))
(code (format "#%x" (char-after (point))))
(dec (get-char-code-property (char-after (point)) 'decomposition))
(info (concat
char-name
" / "
code
" / descomp: "
dec
"\s"
(mapconcat (lambda (cod)
(format "#%x" cod))
dec "\s+\s"))))
(message info)))
Best regards,
Juan Manuel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-07-15 0:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-13 10:49 [tip/offtopic] A function to describe the characters of a word at point Juan Manuel Macías
2022-07-14 15:42 ` Marcin Borkowski
2022-07-14 22:30 ` Samuel Wales
2022-07-15 0:56 ` Juan Manuel Macías
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.