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

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

Break code lines fluently


From: Andrey Tykhonov
Subject: Break code lines fluently
Date: Wed, 12 Mar 2014 07:42:56 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

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!



reply via email to

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