[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Pass replacement string stored an alist to another list
From: |
uzibalqa |
Subject: |
Pass replacement string stored an alist to another list |
Date: |
Sun, 21 Aug 2022 11:47:27 +0000 |
I want to take word at point, search if it exists in an alist and transfer the
replacement string to another list.
This is the code I am using
(defconst alist-tablet-1
'( ("all" . "l") ("as" . "as") ("can" . "k")
("do" . "do") ("for" . "f") ("in" . "n")
("is" . "s") ("it" . "t") ("know" . "no")
("like" . "lk") ("little" . "ll") ("more" . "mo")
("other" . "O") ("some" . "so") ("than" . "n")
("that" . "ta") ("there" . "tr") ("this" . "th")
("time" . "ti") ("to" . "to") ("we" . "w")
("well" . "l") ("will" . "l") ("work" . "wk")
("you" . "u") ))
(defun shorten-word ()
"Shorten word at point but matching with alist-tablet-1."
(interactive)
(let* ( (bounds (bounds-of-thing-at-point 'word))
(word (buffer-substring (car bounds) (cdr bounds))) )
(goto-char (car bounds))
(add-to-list 'nscrip word)
(add-to-list 'nscrip
(s-replace-regexp
word (cdr (assoc word alist-tablet-1))
word))))
I am using (cdr (assoc word alist-tablet-1)) to determine the replacement
string if word exists
in the car element by calling (assoc word alist-tablet-1).
Is this a good scheme to transfer the replacement to the list `nscrip'. Or is
the code not efficient?
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Pass replacement string stored an alist to another list,
uzibalqa <=