all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Popup last command
@ 2010-12-22 16:16 Andrea Crotti
  0 siblings, 0 replies; only message in thread
From: Andrea Crotti @ 2010-12-22 16:16 UTC (permalink / raw)
  To: help-gnu-emacs

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




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

only message in thread, other threads:[~2010-12-22 16:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-22 16:16 Popup last command Andrea Crotti

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.