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

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

Re: Fire defun by typing keyword


From: Emanuel Berg
Subject: Re: Fire defun by typing keyword
Date: Fri, 01 Nov 2013 19:58:58 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Again, it would work just as abbrev, only instead of
>> a table lookup and replace, it would trigger a defun.
>
> An abbrev can have a "hook", which is indeed a
> function that gets called after inserting the
> expansion.  So, you can do the above with an abbrev
> like
>
>   ("mydate" "" date)

Cool! I took a break from "dead-serious hacking" a
couple of days and solved this problem with the help of
the idle timer you told me about earlier. This
"solution" is not one I would recommend to anyone, but
it was interesting to see that the idle timer indeed
worked exactly as expected.

(defun word-to-defun (word)
  (if (string= word "thedate")
      (progn
        (backward-kill-word 1)
        (date)) ))

(defun read-last-word ()
  (save-excursion
    (backward-word)
    (string-make-multibyte (thing-at-point 'word)) ))

(defun read-trigger-last-word ()
  (interactive)
  (word-to-defun (read-last-word)) )

(run-with-idle-timer 1 t 'read-trigger-last-word)

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573


reply via email to

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