unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Properly indenting a defun (sexp tips)
@ 2006-10-15 22:40 Tim Johnson
  2006-10-16  0:16 ` Drew Adams
  2006-10-16  0:39 ` Dieter Wilhelm
  0 siblings, 2 replies; 4+ messages in thread
From: Tim Johnson @ 2006-10-15 22:40 UTC (permalink / raw)


I have a piece of code that looks like this:
;; code:
(defun mu-modifier-char ()
  "Create colorized modifier symbol"
  (interactive)
  (let (my-char)
	(save-excursion
	  (backward-char 1)
	  (setq my-char (char-at))
	  (cond ((member my-char mu-modifiers)
			 (upcase my-char)
			 )
			)
	)))
;; And I want it to look like this
(defun mu-modifier-char ()
  "Create colorized modifier symbol"
  (interactive)
  (let (my-char)
	(save-excursion
	  (backward-char 1)
	  (setq my-char (char-at))
	  (cond ((member my-char mu-modifiers)
			 (upcase my-char))))))
;; that is, properly indented per emacs-lisp-mode

Is there a single command to do this?
If not, being pointed to pertinent documentation
and URLs to discussions on this topic would be
most welcome.

Thanks
tim

-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com

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

* RE: Properly indenting a defun (sexp tips)
  2006-10-15 22:40 Properly indenting a defun (sexp tips) Tim Johnson
@ 2006-10-16  0:16 ` Drew Adams
  2006-10-16  0:39 ` Dieter Wilhelm
  1 sibling, 0 replies; 4+ messages in thread
From: Drew Adams @ 2006-10-16  0:16 UTC (permalink / raw)


    I have a piece of code that looks like this:
    ;; code:
    (defun mu-modifier-char ()
      "Create colorized modifier symbol"
      (interactive)
      (let (my-char)
    	(save-excursion
    	  (backward-char 1)
    	  (setq my-char (char-at))
    	  (cond ((member my-char mu-modifiers)
    			 (upcase my-char)
    			 )
    			)
    	)))
    ;; And I want it to look like this
    (defun mu-modifier-char ()
      "Create colorized modifier symbol"
      (interactive)
      (let (my-char)
    	(save-excursion
    	  (backward-char 1)
    	  (setq my-char (char-at))
    	  (cond ((member my-char mu-modifiers)
    			 (upcase my-char))))))
    ;; that is, properly indented per emacs-lisp-mode

    Is there a single command to do this?
    If not, being pointed to pertinent documentation
    and URLs to discussions on this topic would be
    most welcome.

I don't believe so. But if you want to do this in Lisp, then you might make
use of function `fixup-whitespace', calling it at appropriate places.

Another thing you might try if working in Lisp, is using a pretty-print
function on the (uncompiled) function definition. `symbol-function' will
probably do what you want here. Then just substitute the function name for
`lambda'. This will lose any comments, however.

It all depends on how much you need to do this, and whether you are doing it
by program or interactively. If working interactively, and there are only a
few examples and they are all like this one (with just extra whitespace
before right parens), what I would do is get rid of the lines at the end
that have just parens (`C-k'), and then add parens at the end of your
function until a paren matches the opening paren around `defun'.

If you are working interactively and there are lots of such examples, but
all are similar to this one (just extra whitespace), I'd define a command
that calls `fixup-whitespace' at the right places. Or I'd bind
`fixup-whitespace' to a key and then use a keyboard macro that searches for
the extra whitespace.

Here are some things that can help with matching up parentheses, though you
are probably already aware of them:

- Library `paren.el' helps a lot with parenthesis matching. Turn on
parenthesis highlighting with (show-paren-mode 1) in your .emacs. You can
customize variable `show-paren-style' and face `show-paren-match-face'.

- Another parenthesis-highlighting library, which I don't happen to use, is
`mic-paren.el'.

- In addition to paren highlighting, setting variable `blink-matching-paren'
to non-nil causes the matching left parenthesis to flash when you insert a
right parenthesis.

See the Emacs manual, node Matching, for more information on matching
parens.

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

* Re: Properly indenting a defun (sexp tips)
  2006-10-15 22:40 Properly indenting a defun (sexp tips) Tim Johnson
  2006-10-16  0:16 ` Drew Adams
@ 2006-10-16  0:39 ` Dieter Wilhelm
  2006-10-16  1:12   ` Drew Adams
  1 sibling, 1 reply; 4+ messages in thread
From: Dieter Wilhelm @ 2006-10-16  0:39 UTC (permalink / raw)
  Cc: help-gnu-emacs

Tim Johnson <tim@johnsons-web.com> writes:

> I have a piece of code that looks like this:
> ;; code:
> (defun mu-modifier-char ()
>   "Create colorized modifier symbol"
>   (interactive)
>   (let (my-char)
> 	(save-excursion
> 	  (backward-char 1)
> 	  (setq my-char (char-at))
> 	  (cond ((member my-char mu-modifiers)
> 			 (upcase my-char)
> 			 )
> 			)
> 	)))


> ;; And I want it to look like this
> (defun mu-modifier-char ()
>   "Create colorized modifier symbol"
>   (interactive)
>   (let (my-char)
> 	(save-excursion
> 	  (backward-char 1)
> 	  (setq my-char (char-at))
> 	  (cond ((member my-char mu-modifiers)
> 			 (upcase my-char))))))
> ;; that is, properly indented per emacs-lisp-mode
>
> Is there a single command to do this?

Not exactly a single one but place your cursor in the last line of the
defun and type 3 times M-^.

-- 
    Best wishes

    H. Dieter Wilhelm
    Darmstadt, Germany

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

* RE: Properly indenting a defun (sexp tips)
  2006-10-16  0:39 ` Dieter Wilhelm
@ 2006-10-16  1:12   ` Drew Adams
  0 siblings, 0 replies; 4+ messages in thread
From: Drew Adams @ 2006-10-16  1:12 UTC (permalink / raw)
  Cc: help-gnu-emacs

    Not exactly a single one but place your cursor in the last line of the
    defun and type 3 times M-^.

Good. Forgot about that one.

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

end of thread, other threads:[~2006-10-16  1:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-15 22:40 Properly indenting a defun (sexp tips) Tim Johnson
2006-10-16  0:16 ` Drew Adams
2006-10-16  0:39 ` Dieter Wilhelm
2006-10-16  1:12   ` Drew Adams

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).