unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Can emacs open a new line below or above the current line?
@ 2006-12-21  7:45 Ronald
  2006-12-21  9:06 ` Mathias Dahl
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Ronald @ 2006-12-21  7:45 UTC (permalink / raw)


Better if it can be indented automatically (for example in cc mode).

I get a habit that code the main ones first, and then add on the 
trivialities. For example:

if((n=write(fd,line,n))!=n){
	perror("write error\n");		//second
	exit(-1);				//first
}

This may also applies when I type:

a.
	if(){}
b.
	if(){
	|}		//`|' as the cursor
c.
	Then I'd like to open a line above indented automatically.
	It normally would be C-j C-p tab. Just too many key strokes.

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: Can emacs open a new line below or above the current line?
@ 2006-12-21 13:06 martin rudalics
  0 siblings, 0 replies; 8+ messages in thread
From: martin rudalics @ 2006-12-21 13:06 UTC (permalink / raw)


I'm using the following:

(defun newline-and-indent-maybe ()
   "Insert newline and re-indent lines if necessary.
On an empty line insert a newline before current line.  At the beginning
of a non-empty line, do `newline-and-indent', move to the beginning of
the line just inserted, and indent that line.  Otherwise, do
`newline-and-indent'.  Fixes up any whitespace at end of old line."
   (interactive)
   (let ((go-back
	 (save-excursion
	   (delete-horizontal-space)
	   (and (bolp) (not (eolp))))))
     (when (and (boundp 'show-paren-overlay-1)
	       (overlayp show-paren-overlay-1))
       ;; Remove `show-paren-overlay-1' to avoid flickering.
       (delete-overlay show-paren-overlay-1))
     (newline-and-indent)
     (when go-back
       (forward-line -1)
       (indent-according-to-mode))))

(global-set-key [?\r] 'newline-and-indent-maybe)

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-12-21 22:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-21  7:45 Can emacs open a new line below or above the current line? Ronald
2006-12-21  9:06 ` Mathias Dahl
2006-12-21  9:24   ` Ronald
2006-12-21  9:15 ` David Hansen
     [not found] ` <mailman.2176.1166693025.2155.help-gnu-emacs@gnu.org>
2006-12-21  9:47   ` Ronald
2006-12-21 13:34 ` Dieter Wilhelm
     [not found] ` <mailman.2179.1166708079.2155.help-gnu-emacs@gnu.org>
2006-12-21 22:24   ` Ronald
  -- strict thread matches above, loose matches on Subject: below --
2006-12-21 13:06 martin rudalics

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).