unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Pass replacement string stored an alist to another list
@ 2022-08-21 11:47 uzibalqa
  0 siblings, 0 replies; only message in thread
From: uzibalqa @ 2022-08-21 11:47 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org


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?






^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-08-21 11:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-21 11:47 Pass replacement string stored an alist to another list uzibalqa

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).