help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Break code lines fluently


From: Andreas Röhler
Subject: Re: Break code lines fluently
Date: Wed, 12 Mar 2014 11:07:12 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

Am 12.03.2014 06:42, schrieb Andrey Tykhonov:

Hi all!

When I've used Eclipse I liked its default key binding "Shift-Enter" which
inserts an empty line (with indentation) after the current line. It is very
easy to implement such function in Emacs, please read, if you're
interested: http://emacsredux.com/blog/2013/03/26/smarter-open-line/ .

I used to use this function. It is, as for me, quite handy while browsing
the code to hit "Shift-Enter" and just insert some piece of code. But what
I really were missing is having the same line opening command but for
elisp. It would be better explain by means of example. Let say I have the
following code:

(defun test ()
   (let ((test t))
     (if test
         (message "True")
       (mes|sage "False"))))

Point is located in the middle of "message" function. And I would like to
insert more code to the `let' form (after the `if'). What I was always
doing in such situations, I did always navigate to the appropriate closing
bracket (in this case closing bracket of the `if') and hit Enter. (Yes,
probably there are more better ways to do that. Please share. It is very
interesting to know). Despite the fact that I quite often investigate emacs
configurations of others, wiki, documentation and packages only today I
found the solution to have possibility to break the lines more fluently. So
having such mentioned code I can execute sequentially the command several
times and have the following code to be ready to be extended in the right
place:

(defun test ()
   (let ((test t))
     (if test
         (message "True")
       (message "False"))
     |))

(First execution of this command breaks a line for "message", the second
execution undos this change, the third execution will break a line for
`if', the fourth undos and fifth will break a line for `let').

The command which I just mentioned is the `smart-return' command from the
`emacs-smart-return' tiny package which I just recently wrote and which you
could find at https://github.com/atykhonov/emacs-smart-return It is a very
thin wrapper around `smart-forward' package (Read:
https://github.com/magnars/smart-forward.el). This is just very initial
version. Thus any comments, suggestions are highly appreciated.


With hope that mentioned functionality will be helpful and useful,
Andrey.


Thanks!



Very interesting, thanks!



reply via email to

[Prev in Thread] Current Thread [Next in Thread]