Premises:
My Emacs has a small bug (cannot go up from inside of ""
) in one of its original defun (up-list
). This defun is vital to one of my frequently used command (backward-up-list
) which is bound to C-M-u.
Therefore, I wanted to achieve below objectives:
- Write a NEW defun named
my-up-list
which has the bug fix; - RE-write the native defun
backward-up-list
to call the above new defun (instead of the native buggyup-list
). (By RE-writing under the same defun name, I intend to preserve its original convenient key bindings.)
By following the Emacs Tutorial Here, I implemented it as below:
- I wrote a new defun
my-up-list
inside .emacs file; (see code in the end) - I rewrote the defun
backward-up-list
under a the same name inside .emacs file; (see code in the end).
However, when wI tested it out by trying it in "|"
(| is the cursor position), I encounter below error:
backward-up-list: Wrong number of arguments: (lambda nil (interactive) (let ((s (syntax-ppss))) (if (nth 3 s) (progn (goto-char (nth 8 s))))) (condition-case nil (progn (up-list)) (error nil))), 1 [2 times]
Question:
- Is it the correct way to re-write a native defun just by putting the new implementation with the same name in .emacs file?
- What may went wrong in my code?
Reference:
(The my-up-list
is from here)
;; I only changed "up-list" to "my-up-list" -modeller
(defun backward-up-list (&optional arg)
"Move backward out of one level of parentheses.
With ARG, do this that many times.
A negative argument means move forward but still to a less deep spot.
This command assumes point is not in a string or comment."
(interactive "^p")
(my-up-list (- (or arg 1))))
;; copied from solution to another question - modeller
(defun my-up-list ()
(interactive)
(let ((s (syntax-ppss)))
(when (nth 3 s)
(goto-char (nth 8 s))))
(ignore-errors (up-list)))