From owner-freebsd-questions Mon Jun 18 7:16:53 2001 Delivered-To: freebsd-questions@freebsd.org Received: from dsl-64-193-218-89.telocity.com (dsl-64-193-218-89.telocity.com [64.193.218.89]) by hub.freebsd.org (Postfix) with SMTP id 3CB4A37B401 for ; Mon, 18 Jun 2001 07:16:49 -0700 (PDT) (envelope-from lucas@slb.to) Received: (qmail 30747 invoked by uid 1000); 18 Jun 2001 14:17:03 -0000 Date: Mon, 18 Jun 2001 09:17:03 -0500 From: Lucas Bergman To: jcm@FreeBSD-uk.eu.org Cc: questions@freebsd.org Subject: Re: emacs indentation question Message-ID: <20010618091703.B19099@billygoat.slb.to> Reply-To: lucas@slb.to References: <20010614180524.A43569@dogma.freebsd-uk.eu.org> <20010614181955.A2100@billygoat.slb.to> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010614181955.A2100@billygoat.slb.to>; from lucas@slb.to on Thu, Jun 14, 2001 at 06:19:55PM -0500 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG > > When in C/C++ mode, TAB indents to where emacs thinks the text > > should go. How do you add extra tabs at the end of a line, say, > > to line up a group of variable names or #define values? > > Emacs doesn't line up that sort of thing automatically, AFAIK. You > can run your program through indent(1), of course, or you can write > Emacs functions to do what you want. For example, I banged this out > to align a block of #define's: > > (defun slb-c-align-defines-region () > [... schnipp ...] Mea culpa. I just realized that the slb-c-align-defines-region function I posted was an intermediate version that had bugs. Here's the real one: (defun slb-c-align-defines-region (start end) " Align #define values in the current region." (interactive "r") (save-excursion (let ((maxlen 0) (defre "^#[ \t]*define[ \t]+\\([^ \t]+\\)[ \t]+\\(.*\\)$") (padding "") (numspaces 0)) (goto-char start) (while (re-search-forward defre end t) (let ((elen (- (match-end 1) (match-beginning 1)))) (when (> elen maxlen) (setq maxlen elen)))) (goto-char start) (setq padding (make-string (+ 2 maxlen) ?\ )) ;; ;; Taking two regexp searching passes through the region... I'm ;; ashamed of myself. ;; (while (re-search-forward defre end t) (setq numspaces (- maxlen (- (match-end 1) (match-beginning 1)))) (replace-match (concat "#define " (match-string 1) (substring padding 0 (1+ numspaces)) (match-string 2)))))) nil) I'm not trying to contribute gratuitously to off-topic discussion, but I'm trying to keep incorrect stuff out of the archives even more... Lucas To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message