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

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

Popup last command


From: Andrea Crotti
Subject: Popup last command
Date: Wed, 22 Dec 2010 17:16:35 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (darwin)

Thanks to the help of some of the presents some timie ago I came up with
 the following:
--8<---------------cut here---------------start------------->8---

 (defun growl-popup (msg)
  "Pop up a growl notification with MSG, or display an Emacs message.
The \"growlnotify\" program is used if `window-system' is non-nil and
the program is found in `exec-path'; otherwise `message' is used."
  (interactive)
  (if (and window-system (executable-find "growlnotify"))
      (shell-command (concat "growlnotify -a /Applications/Emacs.app/ -m "
                             (shell-quote-argument msg)))
    (message msg)))

(defun popup-last ()
  (interactive)
  (let
      ((last-key (key-description (this-command-keys))))
    ;; check if we don't have a "stupid" sequence
    (unless
        (= (length (this-command-keys-vector)) 1)
        (growl-popup last-key))))

(setq growl-mode nil)

(defun growl ()
  (interactive)
  (if (not growl-mode)
      (progn
        (message "enabling growl mode notification")
        (add-hook 'pre-command-hook 'popup-last)
        (setq growl-mode t))
    (progn
      (setq-default pre-command-hook (remq 'popup-last pre-command-hook))
      (message "disabling growl mode notification")
      (setq growl-mode nil))))
--8<---------------cut here---------------end--------------->8---

this function growl combined with growl installed on OSX machines can
popup the last command inserted, at the moment only when is at least
composed by two keys, thanks to this:

    (unless
        (= (length (this-command-keys-vector)) 1)
        (growl-popup last-key))))

But I'm not yet completely satisfied.
Sometimes even commands with only one key are important in some modes,
so the idea is maybe that I could instead filter ONLY
"self-insert-command", while all the rest could be anyway interesting.

But I don't get how I can do that, how can I change the two lines above
to get the result desired?

And the other thing is that the switch for enabling/disabling growl
doesn't work like that.

I looked in other code and using a minor-mode it looks much easier, but
I don't get why it doesn't work as I did, what's wrong with that
solution?

Thanks,
Andrea




reply via email to

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