help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Difference between 'C-x e' and 'M-x macro'


From: Barry Margolin
Subject: Re: Difference between 'C-x e' and 'M-x macro'
Date: Wed, 16 Jul 2003 19:43:35 GMT

In article <mailman.131.1058381370.8231.help-gnu-emacs@gnu.org>,
Marco Carbone  <mcarbone@eecs.harvard.edu> wrote:
>Hello all,
>
>This is kind of an odd question but let me explain:
>
>Let's say I have defined a macro whose only event is the function 'up.'

There is no such function.  I assume you mean the "up" key (the up-arrow),
which runs the function "previous-line".

>Then I name the macro 'upmacro' using 'M-x name-last-kbd-macro.'  Now take
>the following bit of code:
>
>  double toss;
>  int t = 1;
>  int flag = 1;X
>
>where X indicates the location of the point.  Then I perform 'C-x e'
>twice.  The point will move as follows:
>
>  double toss;
>  int t = 1;X
>  int flag = 1;
>
>  double toss;X
>  int t = 1;
>  int flag = 1;
>
>So far, so good.  But now let's go back to the original situation:
>
>  double toss;
>  int t = 1;
>  int flag = 1;X
>
>and this time use 'M-x upmacro' twice instead.  Now the point moves
>differently:
>
>  double toss;
>  int t = 1;X
>  int flag = 1;
>
>  double tosX;
>  int t = 1;
>  int flag = 1;
>
>My question is: why?  What's the difference between 'C-x e' and 'M-x
>upmacro?'  

If you use the previous-line/next-line command several times in a row, it
tries to stay in the same column that you originally started in.  If any of
the intermediary lines are too short, it goes to the end, but when it gets
to a line that's long enough it goes back to that original column.  But as
soon as you execute some other command, it forgets about that original goal
column.

The way it determines if you're executing these commands in sequence is by
looking at your recent keystrokes.  Since the keyboard macro emulates
typing, it acts the same way as if you'd pressed the up-arrow key multiple
times.  But when you use M-x, the last keystroke is the Return key that
ended your minibuffer entry.

You'd see the same inconsistency if you compared the up-arrow key itself
with M-x previous-line.

>           Believe it or not, this difference effects an elisp program I'm
>currently working on.  Thanks,

The documentation of previous-line recommends:

  If you are thinking of using this in a Lisp program, consider using
  `forward-line' with a negative argument instead.  It is usually easier
  to use and more reliable (no dependence on goal column, etc.).

Notice that parenthesized remark -- it addresses your issue directly.

-- 
Barry Margolin, barry.margolin@level3.com
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]