Modifying a custom defun to not conflict with Magit
I use the following smart-tab defun in my .emacs for either completion on a word or just to do a standard tab:
(global-set-key [(tab)] 'smart-tab)
(defun smart-tab ()
"This smart tab is minibuffer compliant: it acts as usual in
the minibuffer. Else, if mark is active, indents region. Else if
point is at the end of a symbol, expands it. Else indents the
current line."
(interactive)
(if (minibufferp)
(unless (minibuffer-complete)
(dabbrev-expand nil))
(if mark-active
(indent-region (region-beginning)
(region-end))
(if (looking-at "\\_>")
(dabbrev-expand nil)
(indent-for-tab-command)))))
However, when I'm using magit-status
for git Git integration, I could previously select a file that has had a modification, hit tab, and instantly see a dif开发者_开发百科f on that file to see what's been modified. However, whenever I attempt a tab now, I get the following error in my mini-buffer.
indent-relative: Buffer is read-only: #<buffer *magit: my_project*
Any thoughts on approaching this and maybe applying smart-tab above to certain modes only?
Thanks!
I am the maintainer of smart-tab, available from GitHub. The latest version defines a minor mode which turns itself off in a read-only buffer or the minibuffer, allowing things like ido-mode and magit to work properly. It also is better at handling situations where you want the key run a different command than indent-for-tab-command
, such as org-mode. I highly recommend you use the GitHub version, as it avoids a lot of the headaches of the basic version with a global keybinding.
精彩评论