* Is it possible to set a "goal column" for 'beginning-of-line'?
@ 2005-11-22 12:50 Herbert Euler
2005-11-22 15:35 ` Henrik Enberg
0 siblings, 1 reply; 11+ messages in thread
From: Herbert Euler @ 2005-11-22 12:50 UTC (permalink / raw)
Hello everyone,
The command 'beginning-of-line' moves point to column 0
by default. Is it possible to set a "goal column," so that
this command moves point to that column, e.g. column 7,
rather than 0? The content before such column will become
irreachable in this situation (but it might still be displayed).
In another word, is there a vertical version of narrowing
(but perhaps don't try to hide something)?
Thanks in advance.
Regards,
Guanpeng Xu
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Is it possible to set a "goal column" for 'beginning-of-line'?
2005-11-22 12:50 Herbert Euler
@ 2005-11-22 15:35 ` Henrik Enberg
2005-11-22 17:46 ` Henrik Enberg
0 siblings, 1 reply; 11+ messages in thread
From: Henrik Enberg @ 2005-11-22 15:35 UTC (permalink / raw)
> From: "Herbert Euler" <herberteuler@hotmail.com>
> Date: Tue, 22 Nov 2005 20:50:53 +0800
>
> The command 'beginning-of-line' moves point to column 0
> by default. Is it possible to set a "goal column," so that
> this command moves point to that column, e.g. column 7,
> rather than 0? The content before such column will become
> irreachable in this situation (but it might still be displayed).
(goto-char (+ (line-beginning-position) 7))
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Is it possible to set a "goal column" for 'beginning-of-line'?
2005-11-22 15:35 ` Henrik Enberg
@ 2005-11-22 17:46 ` Henrik Enberg
2005-11-26 9:58 ` Herbert Euler
0 siblings, 1 reply; 11+ messages in thread
From: Henrik Enberg @ 2005-11-22 17:46 UTC (permalink / raw)
> From: Henrik Enberg <henrik.enberg@telia.com>
> Date: Tue, 22 Nov 2005 16:35:18 +0100 (CET)
>
> > From: "Herbert Euler" <herberteuler@hotmail.com>
> > Date: Tue, 22 Nov 2005 20:50:53 +0800
> >
> > The command 'beginning-of-line' moves point to column 0
> > by default. Is it possible to set a "goal column," so that
> > this command moves point to that column, e.g. column 7,
> > rather than 0? The content before such column will become
> > irreachable in this situation (but it might still be displayed).
>
> (goto-char (+ (line-beginning-position) 7))
Eh, I didn't read carefully enough. You wanna read the Emacs Lisp
manual on text properties. The `field' might be of interest. Some
functions like beginning-of-line stop moving when they encounter such a
property.
(info "(elisp) Text Properties")
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Is it possible to set a "goal column" for 'beginning-of-line'?
[not found] <mailman.16320.1132664052.20277.help-gnu-emacs@gnu.org>
@ 2005-11-22 18:29 ` rgb
2005-11-22 20:35 ` Stefan Monnier
1 sibling, 0 replies; 11+ messages in thread
From: rgb @ 2005-11-22 18:29 UTC (permalink / raw)
Herbert Euler wrote:
> Hello everyone,
>
> The command 'beginning-of-line' moves point to column 0
> by default. Is it possible to set a "goal column," so that
> this command moves point to that column, e.g. column 7,
> rather than 0? The content before such column will become
> irreachable in this situation (but it might still be displayed).
>
> In another word, is there a vertical version of narrowing
> (but perhaps don't try to hide something)?
This would do what you want globally.
I tried it and it seems dangerous.
(defun avoid-columns-1-7 ()
(when (< (current-column) 7)
(move-to-column 7 t)))
(add-hook 'post-command-hook 'avoid-columns-1-7)
You probably want to limit it to a mode by using a more
restrictive `when' condition like this:
(and (string= mode-name "FOO") (< (current-column) 7))
Or maybe having it look at some variable that you can toggle.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Is it possible to set a "goal column" for 'beginning-of-line'?
[not found] <mailman.16320.1132664052.20277.help-gnu-emacs@gnu.org>
2005-11-22 18:29 ` rgb
@ 2005-11-22 20:35 ` Stefan Monnier
2005-11-23 2:16 ` Herbert Euler
1 sibling, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2005-11-22 20:35 UTC (permalink / raw)
> The command 'beginning-of-line' moves point to column 0
> by default. Is it possible to set a "goal column," so that
> this command moves point to that column, e.g. column 7,
> rather than 0? The content before such column will become
> irreachable in this situation (but it might still be displayed).
> In another word, is there a vertical version of narrowing
> (but perhaps don't try to hide something)?
There are many different ways to get this behavior, so you'll need to be
more specific if you want to know what's the best option for you.
Things that matter:
- do you want all programatic uses of beginning-of-line to be affected or
only the interactive C-a command?
- what about other commands like C-f and C-b? Should they be allowed to
move through the first 8 chars of a line?
- are those first 8 chars real? I.e. do they get loaded from/saved into
a file?
- should they be shown or should they be ideally hidden?
I.e. tell us more about the bigger picture of what you're trying to do.
Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Is it possible to set a "goal column" for 'beginning-of-line'?
2005-11-22 20:35 ` Stefan Monnier
@ 2005-11-23 2:16 ` Herbert Euler
2005-11-23 2:32 ` Herbert Euler
0 siblings, 1 reply; 11+ messages in thread
From: Herbert Euler @ 2005-11-23 2:16 UTC (permalink / raw)
Thank all of you.
>From: Stefan Monnier <monnier@iro.umontreal.ca>
>To: help-gnu-emacs@gnu.org
>Subject: Re: Is it possible to set a "goal column" for 'beginning-of-line'?
>Date: Tue, 22 Nov 2005 15:35:46 -0500
>
>There are many different ways to get this behavior, so you'll need to be
>more specific if you want to know what's the best option for you.
>Things that matter:
>- do you want all programatic uses of beginning-of-line to be affected or
> only the interactive C-a command?
>- what about other commands like C-f and C-b? Should they be allowed to
> move through the first 8 chars of a line?
>- are those first 8 chars real? I.e. do they get loaded from/saved into
> a file?
>- should they be shown or should they be ideally hidden?
>
>I.e. tell us more about the bigger picture of what you're trying to do.
Actually I'm using php-mode within html-mode, plus mmm-mode.
Now the identation of PHP code is poor in this condition. After
reading some code doing the identing job I found it is possible
to solve this by set such a "goal column," since most of them
count the column from column 0 by go to there with 'beginning-
of-line'. If we could set this column, a few modifications to mmm-
mode will make it handle identation better.
Another method is to modify the identing code to use another
function to go to the "beginning" of a line instead of 'beginning-
of-line', but this could be more difficult.
I'll take a look at the field property now. But 'avoid-columns-1-7'
is not proper due to my confusing description.
Regards,
Guanpeng Xu
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Is it possible to set a "goal column" for 'beginning-of-line'?
2005-11-23 2:16 ` Herbert Euler
@ 2005-11-23 2:32 ` Herbert Euler
0 siblings, 0 replies; 11+ messages in thread
From: Herbert Euler @ 2005-11-23 2:32 UTC (permalink / raw)
>But 'avoid-columns-1-7' is not proper due to my confusing description.
It seems 'avoid-columns-1-7' is able to afford this after being generalized,
although that is not a good manner (I mean, adding such a command to
'post-command-hook' is not elegant since it prevents moving to there only,
and such content might still be modified; besides, it is really dangerous).
Regards,
Guanpeng Xu
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Is it possible to set a "goal column" for 'beginning-of-line'?
[not found] <mailman.16414.1132712222.20277.help-gnu-emacs@gnu.org>
@ 2005-11-23 7:25 ` Stefan Monnier
2005-11-23 8:51 ` Herbert Euler
0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2005-11-23 7:25 UTC (permalink / raw)
> Actually I'm using php-mode within html-mode, plus mmm-mode.
> Now the identation of PHP code is poor in this condition. After
> reading some code doing the identing job I found it is possible
> to solve this by set such a "goal column," since most of them
> count the column from column 0 by go to there with 'beginning-
> of-line'. If we could set this column, a few modifications to mmm-
> mode will make it handle identation better.
I have trouble understanding your description, but it seems the best
approach is to hack the indentation code directly.
Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Is it possible to set a "goal column" for 'beginning-of-line'?
2005-11-23 7:25 ` Stefan Monnier
@ 2005-11-23 8:51 ` Herbert Euler
0 siblings, 0 replies; 11+ messages in thread
From: Herbert Euler @ 2005-11-23 8:51 UTC (permalink / raw)
>From: Stefan Monnier <monnier@iro.umontreal.ca>
>To: help-gnu-emacs@gnu.org
>Subject: Re: Is it possible to set a "goal column" for 'beginning-of-line'?
>Date: Wed, 23 Nov 2005 02:25:14 -0500
>
>I have trouble understanding your description, but it seems the best
>approach is to hack the indentation code directly.
I'll try to explain it more clearly as follows.
Typically a php file contains content like this:
<html>
<body>
<h1><?php
if (something) {
action;
} else {
action;
}
?></h1>
</body>
</html>
There are lots of elements in such files,
e.g. HTML tags, PHP codes, and many other
things (they are not shown here). We can
provide a major mode to handle this well,
but it means lots of existing work on each
major mode could not help. Fortunately,
mmm minor mode can glue several major modes
together. With mmm minor mode, Emacs behaves
like in HTML mode when point is between
<html> and <h1> or between </h1> and </html>
in the above example, and behaves like in
PHP mode when point is between <?php and ?>.
If there are more elements in this file e.g.
C code, Emacs can behave like in C mode as
well. So it can be very useful of mmm mode.
As you see, code between '<?php' and '?>'
should be idented more than <h1>. But if
you really put point before 'if (something)'
and press <TAB>, it will be idented to
column 0. That's why I said it's poor. This
is because ident commands first go to
column 0 with 'beginning-of-line' and then
count columns starting from there.
To solve this, we must modify mmm-mode itself,
since it's the responsibility of mmm-mode
to provide information of which column one line
should be idented to. But either progmodes
or Emacs itself must be modified as well if
there is no vertical narrowing, because as far
as I know all progmodes use 'beginning-of-line'
to address the first location of a line.
Options:
1. Modify all progmodes, so that each of them
uses another function instead of 'beginning-
of-line' to go to the beginning of a line,
and then count columns. This function would
read a variable specifies which column is
the beginning of a line (but actually that's
not necessary since the same information
of which column is the starting column would
be shared by several lines in practice).
2. Modify 'beginning-of-line' so that it reads
the variable in option 1.
Both could be difficult tasks, but option 1
seems to be more diffcult than option 2. But
before doing that, I'd like to ask whether
Emacs has provided such a feature so that
only mmm-mode itself is needed to be modified.
Regards,
Guanpeng Xu
_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now!
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Is it possible to set a "goal column" for 'beginning-of-line'?
2005-11-22 17:46 ` Henrik Enberg
@ 2005-11-26 9:58 ` Herbert Euler
0 siblings, 0 replies; 11+ messages in thread
From: Herbert Euler @ 2005-11-26 9:58 UTC (permalink / raw)
>From: Henrik Enberg <henrik.enberg@telia.com>
>To: help-gnu-emacs@gnu.org
>Subject: Re: Is it possible to set a "goal column" for 'beginning-of-line'?
>Date: Tue, 22 Nov 2005 18:46:16 +0100 (CET)
>
>Eh, I didn't read carefully enough. You wanna read the Emacs Lisp
>manual on text properties. The `field' might be of interest. Some
>functions like beginning-of-line stop moving when they encounter such a
>property.
>
>(info "(elisp) Text Properties")
Now I have known the effect of text properties, and perhaps this
feature can help me fix the identation problem in mmm-mode. Only
mmm-mode needs to be modified in this manner :-)
But before modifying, I want to ask the final question: are there
many situations using the field properties? If so, using field in mmm-
mode to solve the identation problem might damage other
applications, because the name of two text properties cannot be
same, and other applications will not work if field property is
overwritten.
To Stefan:
Actually I want to modify mmm-mode so that it set field property
for php code etc, and leave field property for "the left margin"
part nil. This might work, but I'm not sure, since the identation
might behave strangely if one put point in "the left margin"
and ident there. This is because other commands like 'backward-
char' are not affected by field property. So I think adding a
variable so that all moving commands read it before moving
is still feasible.
Regards,
Guanpeng Xu
_________________________________________________________________
Don't just search. Find. Check out the new MSN Search!
http://search.msn.click-url.com/go/onm00200636ave/direct/01/
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Is it possible to set a "goal column" for 'beginning-of-line'?
[not found] <mailman.16440.1132735879.20277.help-gnu-emacs@gnu.org>
@ 2005-12-01 15:49 ` Stefan Monnier
0 siblings, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2005-12-01 15:49 UTC (permalink / raw)
> I'll try to explain it more clearly as follows.
> Typically a php file contains content like this:
> <html>
> <body>
> <h1><?php
> if (something) {
> action;
> } else {
> action;
> }
> ?></h1>
> </body>
> </html>
> As you see, code between '<?php' and '?>'
> should be idented more than <h1>. But if
> you really put point before 'if (something)'
> and press <TAB>, it will be idented to
> column 0. That's why I said it's poor. This
> is because ident commands first go to
> column 0 with 'beginning-of-line' and then
> count columns starting from there.
I see. While I'd be quite happy to see the PHP code at column 0, I can
understand that some people may prefer it to be somewhere else.
But I think the problem is slightly more complex than what you describe:
- indentation code typically uses `current-column' and `current-indentation'
to figure out the indentation of previous lines (and then compute the
desired indentation of the current line) and then `indent-to' or
`indent-line-to' in order to do the actual indentation.
Those are coded directly in C and don't use beginning-of-line.
- [ I don't know php-mode in particular. ] For some major modes column 0 is
treated specially, typically by assuming that function definitions are at
column 0. So if you really force all indentation to start at column 8,
several things may not work correctly (e.g. font-lock highlighting, imenu,
outline-minor-mode, ...).
- Some indentation algorithms first go back to "the beginning of the
function" or something similar and then move forward from there.
This starting point is often searched with a regexp that assumes that it's
placed at column 0.
For the first point, maybe the best solution is to use `defadvice' on
current-column, current-indentation, and indent-to. In many cases, it
may be sufficient to pretend that the starting point of the PHP block is "at
column 8" and then the indentation algorithm will automatically preserve
this indentation.
For the second point, the only solution I can think of is to really place
the text in column 0. In order for you to see the text in column 8, you can
do things like add an overlay on every newline and place on the overlay an
after-string of " ". So the text will *appear* on screen in column
8, even though in the buffer and in the file it's actually in column 0.
As for using fields, you can try, but I'd be surprised if it works.
Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2005-12-01 15:49 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.16440.1132735879.20277.help-gnu-emacs@gnu.org>
2005-12-01 15:49 ` Is it possible to set a "goal column" for 'beginning-of-line'? Stefan Monnier
[not found] <mailman.16414.1132712222.20277.help-gnu-emacs@gnu.org>
2005-11-23 7:25 ` Stefan Monnier
2005-11-23 8:51 ` Herbert Euler
[not found] <mailman.16320.1132664052.20277.help-gnu-emacs@gnu.org>
2005-11-22 18:29 ` rgb
2005-11-22 20:35 ` Stefan Monnier
2005-11-23 2:16 ` Herbert Euler
2005-11-23 2:32 ` Herbert Euler
2005-11-22 12:50 Herbert Euler
2005-11-22 15:35 ` Henrik Enberg
2005-11-22 17:46 ` Henrik Enberg
2005-11-26 9:58 ` Herbert Euler
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).