3

I use Emacs with Evil mode, and I'm starting new line with key o. But I prefer to stay in Evil's normal mode, without going into Evil's insert mode, when starting a new line.

When reading the called function for new line, I read this:

o runs the command evil-open-below (found in evil-normal-state-map), which is an interactive compiled Lisp function in ‘elpa/evil-20171112.519/evil-commands.el’.

It is bound to o.

(evil-open-below COUNT)

Insert a new line below point and switch to Insert state. The insertion will be repeated COUNT times.

So I thought to create a function that calls Evil's open new line function, then call Normal Mode. Like this:

(defun evil-open-line-in-normal-state (arg)
  (interactive "p")
  (evil-open-below arg)
  (evil-normal-state))

But it inserts a new line at the beginning, instead of new line aligned with the beginning of the text above.

Happily I found another implementation:

(defun smart-open-line (arg)
  "Insert an empty line after the current line.

Position the cursor at its beginning, according to the current mode.

With a prefix ARG open line above the current line."
  (interactive "P")
  (progn
    (move-end-of-line nil)
    (newline-and-indent)))

And Evil stays in the normal state. So everything was well. But after an upgrade to Emacs 27.0.5.0 with new packages, it breaks everything. It gives me a weird errors when starting new lines:

c-guess-basic-syntax: Wrong number of arguments: #[(containing-sexp paren-state) "Æ1\0bÇ1\0È`É\"b0\0\0ÊË
!^\0Ì1/\0È`É\"b03\04\0Ë
!^\0Í=\0Î1M\0È`É\"b0Q\0R\0Ë!^\0Ë
!\0Ï1k\0Ð`ÑÉ#0m\0Ê\0Ò`  ÓZ\"\0Í=\0`*0\0\0,Ô=\0'Ê()*+,+((-Ü\0-@:È\0-@A)-A-Í\0-@)-Ü\0-@(-A-bÕ(\"ì\0Ê¥\0Ö*×ÑØ)#.4ÊfÙ=4*Ö=4×ÑØ)#ÚUÊ.Ë.!#Ø.ËÛ!-Ö.Ê**Ö=ýÊfÜ=HÊ*ä,ZË,!ZÊ*äÊfÝ=äÞ*Þ=ä×ÑØ)#ÚUä/Ë/!ÊÞÔ=¥Êfß=¡ÊfÙ=¥`Sfß=¥ÊÞËà!¯ÞÞá=Ý`âÊx`01`Sfã=ÕÒ01\"?Õä ?+ÝÊÞØ*e*Ö=4×ÑØ)#ÚU4Ê*6*ÊfÜ=Ê¥\0(Ê)(¥\0åæ-!!`+ª\0+." [containing-sexp bracepos c-brace-list-key c-buffer-is-cc-mode csharp-enum-decl-re csharp-type-initializer-statement-re (error) (error) scan-sexps -1 ...] 6], 3

So I thought it was too difficult and time consuming to understand this C-syntax indendation error in PHP-mode when calling smart-open-line.

So I need to start again with the best simple approach:

(defun evil-open-line-in-normal-state (arg)
  (interactive "p")
  (evil-open-below arg)
  (evil-normal-state))

I'm out of ideas, frankly, to implement this while retaining the indentation from line above. What are the best options to retain the indentation when opening a new line?

  • 2
    That is the price you pay when you live at the bleeding edge. indent-line-function is set to php-cautious-indent-line in php-mode. That function calls c-indent-line. Could you try newline-and-indent in c-mode and look whether it throws the same error? If this is the case the right action would be to file a bug-report to bug-cc-mode@gnu.org and wait until the bug is fixed. It is best to subscribe to bug-cc-mode@gnu.org. That is a closed list. Moderator approvals for e-mails from non-subscribers take long there. Tried that for emacs.stackexchange.com/a/36891/2370. – Tobias Nov 23 '17 at 9:51
  • Thanks for your kind reply. However, I wasn't able to install Emacs 26, or even 25.5 properly, and got stucked with Emacs 24.5 which is currently incompatible with my current packages. So instead of incompatible downgrade, there must be a way to modify that simple function above, I guess – ReneFroger Nov 27 '17 at 13:51
  • I still believe correcting smart-open-line is the way to go. Switch on "debug on error" and include the backtrace in your question. – Tobias Nov 27 '17 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.