views:

151

answers:

2

Hi all,

As a vim convert, I've gotten fairly used to viper mode. One issue that I've discovered, however, is that viper-auto-indent breaks all inferior modes. What happens is when I enter any sort of inferior mode (sql-mode, ess-mode, etc.) and hit Enter, the Enter key doesn't actually send the command off to the inferior process and gives the appearance of the process just hanging.

Without setting viper-auto-indent I have the problem that the Enter key doesn't automatically indent when writing code, meaning that I need to always hit tab after entering a new line, which is annoying. The workaround I've been using is to have viper-auto-indent enabled by default (since I spend most of my time programming), and then disabling it when I enter an inferior-mode buffer.

Does anyone know how to fix this problem? Alternatively, can anyone help supply me with the elisp to disable viper-auto-indent when switching to an interior mode buffer, and enabling it when in a non-inferior mode buffer? Thanks.

+1  A: 

I think Emacs' intent is to have you use "C-j" for newline-and-indent, and let Enter be left alone.

If that is not yet acceptable to you, then this untested code may work:

(add-hook 'inferior-ess-mode-hook
               '(lambda () (set (make-local-variable 'viper-auto-indent) nil))
huaiyuan
+1  A: 

I'm not able to reproduce your problem. I tried every level of viper-mode (1-5), and a number of inferior processes. That said, from your actual question, this code appears like it should fit the bill. If/when 'viper-autoindent is called, if the current buffer has a process, it calls the original binding for the keys just pressed. If there's no process, the original viper-autoindent is called.

(defadvice viper-autoindent (around viper-autoindent-but-not-when-buffer-has-process activate)
  "work around reported user problem"
  (if (and (this-command-keys)
           (get-buffer-process (current-buffer)))
      (let* ((viper-mode nil)
             (thiskey (key-binding (this-command-keys))))
        (when thiskey
          (call-interactively thiskey)))
    ad-do-it))
Trey Jackson