unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Indenting Strings (How to?)
@ 2003-12-29 15:32 Dan Anderson
  2003-12-29 17:50 ` Barry Margolin
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Anderson @ 2003-12-29 15:32 UTC (permalink / raw)



        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.

Thanks in advance,

Dan

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

* Re: Indenting Strings (How to?)
  2003-12-29 15:32 Indenting Strings (How to?) Dan Anderson
@ 2003-12-29 17:50 ` Barry Margolin
  2003-12-30  3:07   ` Dan Anderson
  0 siblings, 1 reply; 5+ messages in thread
From: Barry Margolin @ 2003-12-29 17:50 UTC (permalink / raw)


In article <m2r7ynvdv4.fsf@syr-24-59-76-83.twcny.rr.com>,
 Dan Anderson <dan@mathjunkies.com> 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.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA

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

* Re: Indenting Strings (How to?)
  2003-12-29 17:50 ` Barry Margolin
@ 2003-12-30  3:07   ` Dan Anderson
  2003-12-30  3:49     ` Martin Stone Davis
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Anderson @ 2003-12-30  3:07 UTC (permalink / raw)


Barry Margolin <barmar@alum.mit.edu> writes:

> In article <m2r7ynvdv4.fsf@syr-24-59-76-83.twcny.rr.com>,
>  Dan Anderson <dan@mathjunkies.com> 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

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

* Re: Indenting Strings (How to?)
  2003-12-30  3:07   ` Dan Anderson
@ 2003-12-30  3:49     ` Martin Stone Davis
  2003-12-30  3:58       ` Martin Stone Davis
  0 siblings, 1 reply; 5+ messages in thread
From: Martin Stone Davis @ 2003-12-30  3:49 UTC (permalink / raw)


Dan Anderson wrote:
> Barry Margolin <barmar@alum.mit.edu> writes:
> 
> 
>>In article <m2r7ynvdv4.fsf@syr-24-59-76-83.twcny.rr.com>,
>> Dan Anderson <dan@mathjunkies.com> 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

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

* Re: Indenting Strings (How to?)
  2003-12-30  3:49     ` Martin Stone Davis
@ 2003-12-30  3:58       ` Martin Stone Davis
  0 siblings, 0 replies; 5+ messages in thread
From: Martin Stone Davis @ 2003-12-30  3:58 UTC (permalink / raw)


Martin Stone Davis wrote:

> Dan Anderson wrote:
> 
>> Barry Margolin <barmar@alum.mit.edu> writes:
>>
>>
>>> In article <m2r7ynvdv4.fsf@syr-24-59-76-83.twcny.rr.com>,
>>> Dan Anderson <dan@mathjunkies.com> 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

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

end of thread, other threads:[~2003-12-30  3:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-12-29 15:32 Indenting Strings (How to?) Dan Anderson
2003-12-29 17:50 ` Barry Margolin
2003-12-30  3:07   ` Dan Anderson
2003-12-30  3:49     ` Martin Stone Davis
2003-12-30  3:58       ` Martin Stone Davis

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