“wrong-type-argument” on an Emacs function I've written

本秂侑毒 提交于 2020-01-23 11:39:51

问题


I'd like my tab key to do the following:

  • If I'm in the minibuffer, use word completion.
  • Otherwise, if a region is selected, indent it.
  • Otherwise, indent the line at the point (using tab-to-tab-stop).

Here's the code, some of which is based on fragments I've found elsewhere on the Internet:

(defun my-tab ()
  "If region is selected, indent it and keep it selected, else indent current line."
  (interactive)
       (if (use-region-p)
           (increase-left-margin (region-beginning) (region-end) nil)
           (tab-to-tab-stop))
        (setq deactivate-mark nil))
(defun my-untab ()
  "If region is selected, unindent it and keep it selected, else unindent current line."
  (interactive)
       (if (use-region-p)
           (decrease-left-margin (region-beginning) (region-end) nil)
         (indent-rigidly (line-beginning-position) (line-end-position) (- tab-width)))
        (setq deactivate-mark nil))
;; AJF: wrote this one myself
(defun ajf-tab-fun ()
   (if (minibufferp)
     (minibuffer-complete)
     (my-tab)))

(global-set-key (kbd "TAB") 'ajf-tab-fun)

The problem is that when I press the tab key, I get an error:

Wrong type argument: commandp, ajf-tab-fun

I set debug-on-error to t so I could debug. Here's the output:

Debugger entered--Lisp error: (wrong-type-argument commandp ajf-tab-fun)
  call-interactively(ajf-tab-fun nil nil)

What should I be doing instead?


回答1:


(defun ajf-tab-fun ()
  (interactive)     ; add interactive to let emacs know to call it interactively
   (if (minibufferp)
     (minibuffer-complete)
     (my-tab)))

You just forgot the (interactive)




回答2:


Actually the behavior you describe is pretty much the default behavior already, except for the "indent" where the default is to "indent according to the major mode indentation rules" instead of "move the text right (or left) by a fixed amount".



来源:https://stackoverflow.com/questions/13077943/wrong-type-argument-on-an-emacs-function-ive-written

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!