magnars / annoying-arrows-mode.el

Emacs gets annoyed when you navigate around your document one char at a time.
10 stars 4 forks source link

It's hard to extend the list of alternatives #1

Open pdcawley opened 12 years ago

pdcawley commented 12 years ago

I have the fastnav suite of navigational tools installed and wanted to add them to the list of less annoying alternatives for the various annoying commands, so rather than just altering the calls to aa-add-annoying-arrows-advice, I did this:

(defun aa--maybe-complain (cmd)
  (if (and (memq this-command annoying-commands)
           (eq this-command last-command))
      (progn
        (incf annoying-arrows--current-count)
        (when (> annoying-arrows--current-count annoying-arrows-too-far-count)
          (beep 1)
          (let* ((alts (aa--commands-with-shortcuts (get cmd 'aa--alts)))
                 (alt (nth (random (length alts)) alts))
                 (key (substitute-command-keys (format "\\[%S]" alt))))
            (message "Annoying! How about using %S (%s) instead?" alt key))))
    (setq annoying-arrows--current-count 0)))

(defmacro add-annoying-arrows-advice (cmd alternatives)
  `(progn
     (add-to-list 'annoying-commands (quote ,cmd))
     (put (quote ,cmd) 'aa--alts ,alternatives)
     (defadvice ,cmd (before annoying-arrows activate)
       (when annoying-arrows-mode
         (aa--maybe-complain (quote ,cmd))))))

(defun aa-add-suggestion (cmd alternative)
  (let ((old-alts (or (get cmd 'aa--alts)
                      ())))
    (unless (memq alternative old-alts)
      (put cmd 'aa--alts (cons alternative old-alts)))))

And then I could do (aa-add-suggestion next-line 'fastnav-jump-to-char-backward) in my config files and not have to worry about editing annoying-arrows.el again. get and put are two of my favourite elisp commands...

magnars commented 12 years ago

This is interesting. I'll have a look at it tonight or tomorrow. I'll also have to check out fastnav. Thanks!

magnars commented 12 years ago

That looks pretty nice. I'd be happy to accept a pull request with this change.

pdcawley commented 12 years ago

Right ho. I'll try and grab the time to make a proper pull tonight.

On 22 June 2012 14:51, Magnar Sveen reply@reply.github.com wrote:

That looks pretty nice. I'd be happy to accept a pull request with this change.


Reply to this email directly or view it on GitHub: https://github.com/magnars/annoying-arrows-mode.el/issues/1#issuecomment-6508043