From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Martin Stone Davis Newsgroups: gmane.emacs.help Subject: Re: Indenting Strings (How to?) Date: Mon, 29 Dec 2003 19:58:29 -0800 Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1072756937 24119 80.91.224.253 (30 Dec 2003 04:02:17 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 30 Dec 2003 04:02:17 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Dec 30 05:02:11 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AbB59-0006jJ-00 for ; Tue, 30 Dec 2003 05:02:11 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AbC1o-0001bA-Rr for geh-help-gnu-emacs@m.gmane.org; Tue, 30 Dec 2003 00:02:48 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AbC1W-0001b5-26 for help-gnu-emacs@gnu.org; Tue, 30 Dec 2003 00:02:30 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AbC0y-0001Nc-Vy for help-gnu-emacs@gnu.org; Tue, 30 Dec 2003 00:02:29 -0500 Original-Received: from [80.91.224.249] (helo=main.gmane.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AbC0y-0001NI-F7 for help-gnu-emacs@gnu.org; Tue, 30 Dec 2003 00:01:56 -0500 Original-Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1AbB3V-0005kA-00 for ; Tue, 30 Dec 2003 05:00:29 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-To: help-gnu-emacs@gnu.org Original-Received: from sea.gmane.org ([80.91.224.252]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AbB3T-0005k0-00 for ; Tue, 30 Dec 2003 05:00:27 +0100 Original-Received: from news by sea.gmane.org with local (Exim 3.35 #1 (Debian)) id 1AbB3T-0006Ed-00 for ; Tue, 30 Dec 2003 05:00:27 +0100 Original-Lines: 93 Original-X-Complaints-To: usenet@sea.gmane.org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031007 X-Accept-Language: en-us, en In-Reply-To: X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:15628 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:15628 Martin Stone Davis wrote: > Dan Anderson wrote: > >> Barry Margolin writes: >> >> >>> In article , >>> Dan Anderson wrote: >>> >>> >>>> A lot of times when I'm coding I'll have a very long string or >>>> comments which is some other kind of code (i.e. HTML or CSS embedded >>>> in a Perl CGI script) or is text. Many times I'll try to keep the >>>> indentation neat, but pressing tab in a string (or comments) doesn't >>>> do anything (in CPerl mode, PHP mode, or any other mode). This means >>>> that I end up having to space over manually (a royal PITA). >>>> >>>> Is there a good way to tell emacs to either treat all comments >>>> and strings as normal text (i.e so I can get basic tabbing and >>>> justification), or (even better), to set rules concerning how to treat >>>> comments and strings. >>> >>> >>> Type C-q TAB to insert a literal TAB character. >> >> >> >> Thanks for trying to help but this is not quite what I want. >> I want emacs to automatically tab my code and keep it neat and orderly >> like it does outside of comments and strings. >> >> -Dan > > > Ah, so *that's* what you want. I've always wondered why Emacs isn't set > up to do that automatically. Hopefully this will work for you when > added to .emacs. I coded it myself :) > > ;;BEGIN > (defvar change-start nil) > (defvar change-end nil) > (make-variable-buffer-local 'change-start) > (make-variable-buffer-local 'change-end) > > (defun mlisp-after-change-function (start end pre-change-length) > (setf change-start > (if change-start > (min change-start start) > start)) > (setf change-end > (if change-end > (max change-end end) > end))) > > (defun mlisp-post-command-hook () > (when change-start > (indent-region 0 (buffer-size) nil) > (setf change-start nil) > (setf change-end nil))) > > (add-hook 'after-change-functions 'mlisp-after-change-function nil nil) > (add-hook 'post-command-hook 'mlisp-post-command-hook nil nil) > ;;END > > The m in "mlisp" just stands for me, Martin. The change-start, > change-end were originally there because I wanted to call indent-region > to be a little bit more efficient when it indented. However, I ended up > with very strange indents sometimes when I used `(indent-region > change-start (buffer-size) nil)'. Try it yourself and then position > your point just before the b in: > > (a > b) > (c > d) > > If you hit the spacebar then, you'll find that strangely fourth line > (with the `d') becomes completely unindented. > > But if you use the above code, it should work properly. It's a little > inefficient, but it does the job for me, so far. > > Good luck, and let me know if you find something better. > > -Martin D'oh. I just re-read your post, and I don't think the above addresses your concerns AT ALL. Sorry -Martin