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

Open
pdcawley opened this Issue Jun 21, 2012 · 3 comments

Comments

Projects
None yet
2 participants
@pdcawley
Contributor

pdcawley commented Jun 21, 2012

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

This comment has been minimized.

Show comment Hide comment
@magnars

magnars Jun 21, 2012

Owner

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

Owner

magnars commented Jun 21, 2012

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

@magnars

This comment has been minimized.

Show comment Hide comment
@magnars

magnars Jun 22, 2012

Owner

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

Owner

magnars commented Jun 22, 2012

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

@pdcawley

This comment has been minimized.

Show comment Hide comment
@pdcawley

pdcawley Jun 22, 2012

Contributor

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:
#1 (comment)

Contributor

pdcawley commented Jun 22, 2012

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:
#1 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment