1

Somehow my left mouse click does not work on links anymore. I can put the cursor, hit Return and get a link opened. But a mouse click gives this on the "Message" buffer:

call-interactively: Wrong number of arguments: (1 . 1), 2

I am clueless.

Additional Info

The problem occurs with emacs 24.4 and 24.5 (current running). Setting run M-x toggle-debug-on-error and click on a link gave me this:

Debugger entered--Lisp error: (wrong-number-of-arguments (1 . 1) 2)
  mouse-drag-region(1419 1456)
  call-interactively(mouse-drag-region nil nil)
  command-execute(mouse-drag-region)

Hitting q on back-trace buffer gives inconsistent result so I don't know what to paste here.

  • 1
    You did not mention what emacs version, what major and minor modes are in effect … You could also try to set debug-on-error to t and provoke the error. You get a backtrace that might contain some clues. Type q in the *Backtrace* buffer when done with it, and set debug-on-error back to nil if you don't fancy looking at backtraces every time something goes wrong. – Harald Hanche-Olsen Aug 3 '15 at 12:41
  • @HaraldHanche-Olsen You caught me. I was thinking that this is version indipendent; and I forgot about trying to get some debug messages. Now updated – biocyberman Aug 3 '15 at 13:06
  • Hmm, a little better. But still, what mode? What sort of link? The very best is if you can give a step by step description of how you reproduce the error, starting from emacs -Q. – Harald Hanche-Olsen Aug 3 '15 at 13:08
  • @HaraldHanche-Olsen Getting somewhere. emacs -Q makes the problem go away. I can for example C-h C-a and Click on the Authors link and go the the intended author page. Whereas, in my normal emacs (running without -Q), doing the same thing does not get anywhere and shows the error. – biocyberman Aug 3 '15 at 13:16
  • 2
    Bisect your init file recursively, commenting out 1/2, then 3/4, 7/8,... until you find the expression that introduces the problem. You can use command comment-region to comment out selected text (or uncomment it, with C-u). – Drew Aug 3 '15 at 14:12
2

I hope this is not to send a bad signal. I will answer my own question once more. The comments are very helpful in guiding me, however I have to use both my 'knowledge' of my setup, my laziness, and the good suggestions to come up with the following solution.

  1. At first I thought bisecting as @Drew suggested is a tedious task. So I do M-x package-install RET bug-hunter to do the bisection for me. bug-hunter did not give back any problematic lines:

    M-x bug-hunter-init-file RET e
    Doing some initial tests...
    Test failed.
    No errors signaled after loading the entire file. If you're
    looking for something that's not an error, you need to provide an
    assertion. See this link for some examples:
    https://github.com/Bruce-Connor/elisp-bug-hunter
    
  2. I checked out the assertion part on github, but then I don't know what assertion to put for the problematic function mouse-drag-region.

  3. It seems to be a dead end. But the function name *-region reminds me of some cool function I copied from EmacsWiki some time ago:

    (do-all-symbols (symbol)
      (when (and (commandp symbol t)
                 (string-match-p "-region$\\|kill-ring-save" (symbol-name symbol)))
        (put symbol 'interactive-form
             '(interactive
               (if (use-region-p)
                   (list (region-beginning) (region-end))
                 (list (line-beginning-position) (line-beginning-position 2)))))))
    

    then I opened my .emacs in one instace and start comment that function out. I open another emacs instance and test links. Oh my gosh, it works.

The next question is how to fix the function. There several alternative for the functions on EmacsWiki (i.e. This one: http://emacswiki.org/emacs/CopyingWholeLines). By the way, I find EmacsWiki in many cases confusing because it shows all editing of a page, so it is hard to see which one really works.

Update Following is the fix for both functions on the EmacsWiki that caused me losing some hair. Hope I can find out how/when to edit that EmacsWiki page. For now, here are the fixed functions:

;;;************************************************************
;; Smart copy and paste lines/regions
;; Use `my-kill-ring-save` by uncommenting it if you only want to handle
;; cut and copy the whole line without selecting it explicitly.
;; the `do-all-symbols` loop applies the same approach to all functions
;; that deal with regions. 
;;
;;  (defun my-kill-ring-save (beg end &optional flash)
;;       (interactive (if (use-region-p)
;;                        (list (region-beginning) (region-end) nil)
;;                      (list (line-beginning-position 1)
;;                            (line-beginning-position 2) 'flash)))
;;       (kill-ring-save beg end)
;;       (when flash
;;         (save-excursion
;;           (if (equal (current-column) 0)
;;               (goto-char end)
;;             (goto-char beg))
;;           (sit-for blink-matching-delay))))
;; (global-set-key [remap kill-ring-save] 'my-kill-ring-save)
;; Don't quite understand this code below
(do-all-symbols (symbol)
      (when (and (commandp symbol t)
                 (string-match-p "-region$\\|kill-ring-save" (symbol-name symbol))
         (not (string-match-p "mouse" (symbol-name symbol))))
        (put symbol 'interactive-form
             '(interactive
               (if (use-region-p)
                   (list (region-beginning) (region-end))
                 (list (line-beginning-position) (line-beginning-position 2)))))))
;;;;************************************************************
  • By the way, the Bug-Hunter has an interactive mode which you could have used as well. (The failure message probably should have told you about that) – Malabarba Aug 3 '15 at 18:37
  • 1
    And honestly, whoever put that snippet on the wiki is a cruel sadistic villain. :P – Malabarba Aug 3 '15 at 18:39
  • @Malabarba Very true, so villain!!! but I also learnt much about debugging emacs init file now. I fixed both those evil functions in the updated answer. – biocyberman Aug 3 '15 at 21:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.