Reputation: 2178
I'd like my tab key to do the following:
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?
Upvotes: 3
Views: 2024
Reputation: 28571
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".
Upvotes: 0
Reputation: 21461
(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)
Upvotes: 3