help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Seaching non-existent word in alist gives error


From: uzibalqa
Subject: Seaching non-existent word in alist gives error
Date: Sun, 21 Aug 2022 15:17:35 +0000

I have the function `shorten-word' that is supposed to shorten a word by 
looking at `alist-tablet-1'.
But when the word at point does not exist, I get a Lisp error

(void-function nil) nil(#("owell" 0 5 (fontified t))) 
replace-regexp-in-string(#("owell" 0 5 (fontified t)) nil #("owell" 0 5 
(fontified t))) 
(add-to-list 'nscrip 

What can I do to solve this problem?


    (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 using 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
           (replace-regexp-in-string word (cdr (assoc word alist-tablet-1)) 
word))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]