From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: Properly indenting a defun (sexp tips) Date: Sun, 15 Oct 2006 17:16:25 -0700 Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1160957840 9234 80.91.229.2 (16 Oct 2006 00:17:20 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 16 Oct 2006 00:17:20 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Oct 16 02:17:17 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1GZGAI-0005ar-N1 for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Oct 2006 02:17:11 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GZGAI-0007lQ-2G for geh-help-gnu-emacs@m.gmane.org; Sun, 15 Oct 2006 20:17:10 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GZGA4-0007gI-Qx for help-gnu-emacs@gnu.org; Sun, 15 Oct 2006 20:16:56 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GZGA2-0007dG-W3 for help-gnu-emacs@gnu.org; Sun, 15 Oct 2006 20:16:55 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GZGA2-0007cm-QJ for help-gnu-emacs@gnu.org; Sun, 15 Oct 2006 20:16:54 -0400 Original-Received: from [148.87.113.118] (helo=rgminet01.oracle.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1GZGIz-0001XJ-Ns for help-gnu-emacs@gnu.org; Sun, 15 Oct 2006 20:26:12 -0400 Original-Received: from rgmsgw02.us.oracle.com (rgmsgw02.us.oracle.com [138.1.186.52]) by rgminet01.oracle.com (Switch-3.2.4/Switch-3.1.6) with ESMTP id k9G0GldF012989; Sun, 15 Oct 2006 18:16:47 -0600 Original-Received: from dradamslap (dhcp-amer-csvpn-gw2-141-144-73-159.vpn.oracle.com [141.144.73.159]) by rgmsgw02.us.oracle.com (Switch-3.2.4/Switch-3.2.4) with SMTP id k9G0GkU1027580; Sun, 15 Oct 2006 18:16:46 -0600 Original-To: , X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) In-Reply-To: Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-Whitelist: TRUE X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:38060 Archived-At: 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.