0

I'm trying to write a function that will return the name of a Greek vowel: alpha or epsilon etc. I was hoping this could be done by extracting it from the second group in the following regexp (in a function that determines whether a character is a Greek vowel), but I don't know how, if at all, that is possible.

(defun greek-vowel-p (l)
  (eql (string-match "GREEK \\(SMALL\\|CAPITAL\\) LETTER \
\\(ALPHA\\|EPSILON\\|ETA\\|IOTA\\|OMICRON\\|UPSILON\\|OMEGA\\|RHO\\)"
                     (get-char-code-property l 'name))
       0))
Basil
  • 12,019
  • 43
  • 69
Toothrot
  • 3,204
  • 1
  • 12
  • 30
  • How about?: `(car (last (split-string (get-char-code-property ?α 'name))))` – lawlist Jul 02 '18 at 21:05
  • @lawlist, the name is not necessarily the last word. – Toothrot Jul 02 '18 at 21:08
  • The most common pattern for extracting whole matches or subgroups thereof is `(and (string-match ...) (match-string ...))`; see [`(elisp) Searching and Matching`](https://www.gnu.org/software/emacs/manual/html_node/elisp/Searching-and-Matching.html). – Basil Jul 02 '18 at 21:19
  • @Basil, thanks, I tried something like this, but missed the in-string bit. – Toothrot Jul 02 '18 at 21:33
  • In your case @Basil's comment translates to something like `(defun my-greek-vowel (char) (and (greek-vowel-p char) (match-string 2 (get-char-code-property char 'name))))`. Please write up an answer and accept it if you have a working version. BTW I am not so sure that I would use `greek-vowel-p` at all if that function is not made by myself. If the code of that function changes it may break your code. Example for a breaking change: Adding a `save-match-data` to `greek-vowel-p`. – Tobias Jul 02 '18 at 23:36

1 Answers1

1

Based on comments,

(defun greek-vowel-name (c)
  "Return the name of the Greek vowel character C as a symbol.
The same name is returned regardless of case and diacritics.
If the argument is not a Greek vowel, the value is nil.
The semi-vowel rho is considered a vowel."
  (let ((u (get-char-code-property c 'name)))
    (and (string-match "GREEK \\(?:SMALL\\|CAPITAL\\) LETTER \
\\(ALPHA\\|EPSILON\\|ETA\\|IOTA\\|OMICRON\\|UPSILON\\|OMEGA\\|RHO\\)"
                       u)
         (intern (downcase (match-string 1 u))))))
Drew
  • 75,699
  • 9
  • 109
  • 225
Toothrot
  • 3,204
  • 1
  • 12
  • 30