Tuesday Oct 27, 2009

I've been experimenting with Mercurial Queues with the idea of sharing their mysteries with OpenSolaris developers so we can all integrate multiple changesets and keep one fix per changeset.

Essentially mq allows you to take a snapshot of your changes and create a patch file. You may then make additional changes to be applied to the same patch file (qrefresh) or create a new patch (qnew) These patches may then be removed (qpop) and reapplied (qpush) at your leisure. So that's the theory, lets take a look using an example:

Enabling mq

To enable mq on OpenSolaris simply add it to your extensions in .hgrc:

$ head -2 ~/.hgrc
[extensions]
mq=

Some data to work on.

For the following examples I've created a repository and added to it a simple C 'First program' and a make(1) file to compile and delete the program... Complete with some faults to fix.

$ hg init qexample
$ cd qexample
$ echo 'int\nmain(int argc, char *argv[])\n{\n\tprintf("hello word");\n}'
$ 1> hi.c
$ echo src='hi.c\nbin=${src:%.c=%}\nall: ${bin}\nclobber:\n\trm ${bin}'
$ 1> Makefile
$ hg commit -m 'First program' -u beginner -A hi.c Makefile
$ cd ..

Clone repository and initialise for use with mq

Create a clone of qexample called qex1 and initialise it for mq using qinit -c.

$ hg clone qexample qex1
updating working directory
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cd qex1
$ hg qinit -c

Fix Makefile clobber target

The Makefile has some issues, firstly the clobber target.

$ make clobber hi
rm hi
rm: hi: No such file or directory
*** Error code 2
make: Fatal error: Command failed for target `clobber'

First Patch, Makefile

So here is our first issue, the clobber build fails as 'rm' failed and causes make to exit. To address that we can simply add a -f to rm, so lets do that for our first patch.

$ hg qnew Makefile

The qnew command states we want to create a new patch, the argument is the name of the patch. This action also creates a changeset, don't be concerned about that now.

$ hg log
changeset:   1:d8ddc677fa77
tag:         qtip
tag:         Makefile
tag:         tip
tag:         qbase
user:        Stacey Marshall ‹Stacey.Marshall-AT-Sun-DOT-COM›
date:        Tue Oct 27 21:17:03 2009 +0000
summary:     [mq]: Makefile

changeset:   0:390c5f52f8e3
tag:         qparent
user:        beginner
date:        Tue Oct 27 21:17:02 2009 +0000
summary:     First program

$ sed 's/rm /rm -f /' Makefile > m
$ mv m Makefile
$ make clobber hi
rm -f hi
cc    -o hi hi.c 
"hi.c", line 4: warning: implicit function declaration: printf
$ hg qrefresh

After applying the fix clobber target now works. However, now the compiler's giving us warnings! That's a new issue, so I update the Makefile change using qrefresh and start a new patch:

Second patch, remove warnings.

This time qnew is used with the -m option to add a description. Note this description is also applied to the changeset, it can be changed later if necessary:

$ hg qnew -m 'remove implicit function delcaration warnings' fix1
$ (echo '#include ‹stdio.h›'; cat hi.c) > new.c
$ mv new.c hi.c
$ hg log -l1
changeset:   2:4ffb58a8196f
tag:         qtip
tag:         tip
tag:         fix1
user:        Stacey Marshall ‹Stacey.Marshall-AT-Sun-DOT-COM›
date:        Tue Oct 27 21:17:03 2009 +0000
summary:     remove implicit function declaration warnings

$
$ hg qdiff
diff -r d0b382d0a781 hi.c
--- a/hi.c	Tue Oct 27 21:17:03 2009 +0000
+++ b/hi.c	Tue Oct 27 21:17:03 2009 +0000
-AT--AT- -1,3 +1,4 -AT--AT-
+#include ‹stdio.h›
 int
 main(int argc, char *argv[])
 {
$ make hi
cc    -o hi hi.c 
$ hg qrefresh

The include was added to hi.c to remove the warning, and again the change updated using qrefresh.

Third patch, retrospective patching

Its likely that you'll start making changes before remembering to start a patch with qnew. For those occasions the -f option comes to hand to place all un-committed changes in to the patch. Verified below with qdiff:

$ ./hi
hello word$ # Doh! No new line, and it was meant to say 'world'!
$ sed 's/hello word/Hello world!\\n/' hi.c > new.c
$ mv new.c hi.c
$ hg qnew -f -m 'Fix world' message
$ hg qdiff
diff -r 8a838c77402f hi.c
--- a/hi.c	Tue Oct 27 21:17:03 2009 +0000
+++ b/hi.c	Tue Oct 27 21:17:04 2009 +0000
-AT--AT- -2,5 +2,5 -AT--AT-
 int
 main(int argc, char *argv[])
 {
-	printf("hello word");
+	printf("Hello world!\n");
 }

Listing patches with qseries

The qseries command shows us which patches have been applied, use the -v option to display 'A' (applied) and 'U' (un-applied) flags:

$ hg qseries -v
0 A Makefile
1 A fix1
2 A message
$ cat hi.c
#include ‹stdio.h›
int
main(int argc, char *argv[])
{
	printf("Hello world!\n");
}
$

Traversing the patches to make other changes.

Lets assume we want to make another change to the Makefile, but we want to keep just the one patch for changes to Makefile. To accomplish this we pop the other two patches off. In the following that's done by naming the patch to pop to:

$ hg qpop Makefile
now at: Makefile
$ hg qseries -v
0 A Makefile
1 U fix1
2 U message

Note now that the other two patches are un-applied.

With the just the original patch applied modify the Makefile, update the patch using qrefresh and then re-apply all the other patches using qpush -a.

$(echo '# Makefile example';cat Makefile)>new
$ mv new Makefile
$ hg qrefresh
$ hg qdiff
diff -r 390c5f52f8e3 Makefile
--- a/Makefile	Tue Oct 27 21:17:02 2009 +0000
+++ b/Makefile	Tue Oct 27 21:17:04 2009 +0000
-AT--AT- -1,5 +1,6 -AT--AT-
+# Makefile example
 src=hi.c
 bin=${src:%.c=%}
 all: ${bin}
 clobber:
-	rm ${bin}
+	rm -f ${bin}
$ hg qpush -a

Caution!

Some caution is needed when you want two patches that edit the same file. Its doable but because underneath patch(1) is being used you may need to manually merge in rejects.

Another gotcha on older versions of Mercurial is if you add a file in a patch-queue. If the patch is popped off you may need to re-add it (hg add). Lets see that in action by adding a new file which of course requires adding to the Makefile too... This seems to be fixed however in version 1.3.1:

$ hg qpush -a
applying fix1
applying message
now at: message
$ hg qnew bye
$ sed 's/Hello world/Bye/' hi.c > bye.c
$ hg add bye.c
$ : Make changes to makefile...
$ hg qrefresh
$ hg qpop Makefile
now at: Makefile
$ sed 's/hi.c/hi.c bye.c/' Makefile >new
$ head -2 new
# Makefile example
src=hi.c bye.c
$ mv new Makefile
$ hg qrefresh
$ hg qpush -a
applying fix1
applying message
applying bye
now at: bye
$ hg log bye.c || hg add bye.c # NEED TO CONFIRM!
$ hg log bye.c
changeset:   4:cdb5958dcd87
tag:         qtip
tag:         tip
tag:         bye
user:        Stacey Marshall ‹Stacey.Marshall-AT-Sun-DOT-COM›
date:        Tue Oct 27 21:17:05 2009 +0000
summary:     imported patch bye


$ make
cc    -o hi hi.c 
cc    -o bye bye.c 
$ 

Updating your repository - pull and update.

It is most likely someone is going to have integrated (push) between your original clone and push, and that you'd like to merge those changes.

So Firstly, for the example, add a changeset to our parent repo;

$ hg clone ../qexample tmp
$ cd tmp
$ echo "README...  TBD" > README
$ hg add README
$ hg commit -u beginner -m 'Added README for support.'
$ hg push
$ cd ..
$ hg incoming -v
comparing with /export/home/sm26363/Mercurial/Mercurial/qexample
searching for changes
changeset:   1:2048a9e0068b
tag:         tip
user:        beginner
date:        Tue Oct 27 21:17:05 2009 +0000
files:       README
description:
Added README for support.

$ 

Now Hold onto your seats, this is a bit of roller-coaster ride!

Firstly, we save the series of patches using qsave, with some essential options:

  • -c : Copy Patch directory
  • -n : Specify name of directory - By default it uses patches.N where N is next number in series until an non-existent directory is found within the root .hg directory.
  • -e : Empty the queue status file - The status file holds information about which patches are applied, so deleting it makes it look as though the patch queue is empty. The changesets are stripped of their special tags.

$ hg qsave -e -c -n incoming
copy /export/home/sm26363/Mercurial/Mercurial/qex1/.hg/patches to /export/home/sm26363/Mercurial/Mercurial/qex1/.hg/incoming
$ hg glog --template '{rev}:{node|short} {author|user}\n{desc|firstline}\n\n'
@  5:db6e2d5b6aa2 Stacey
|  hg patches saved state
|
o  4:cdb5958dcd87 Stacey
|  imported patch bye
|
o  3:d20726d3cc4d Stacey
|  Fix world
|
o  2:63144e5ebe68 Stacey
|  remove implicit function declaration warnings
|
o  1:be53b09aed16 Stacey
|  [mq]: Makefile
|
o  0:390c5f52f8e3 beginner
   First program

we're now ready to pull the incoming changes over, DON'T use the -u option. The update needs to be done separately:

$ hg pull
pulling from /export/home/sm26363/Mercurial/Mercurial/qexample
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files (+1 heads)
(run 'hg heads' to see heads, 'hg merge' to merge)
$ hg glog --template "{rev}:{node|short} {author|user}\n{desc|firstline}\n\n"\
 -l3
o  6:2048a9e0068b beginner
|  Added README for support.
|
| @  5:db6e2d5b6aa2 Stacey
| |  hg patches saved state
| |
| o  4:cdb5958dcd87 Stacey
| |  imported patch bye
| |

The pull done, as normal we have multiple heads and possibly files that need merging. But as we're using patches we'll simply overwrite, local changes using option -C and re-apply the patches using qpush with the following arguments:

  • -m : Merge from another queue - This triggers a three-way merge if the patch fails to apply with the applicable changeset. The result is a new patch based on the changes.
  • -n : Name of other-queue - the backup from previous step.
  • -a : All patches.

$ hg update -C tip
3 files updated, 0 files merged, 1 files removed, 0 files unresolved
$ hg qpush -m -n incoming -a
merging with queue at: /export/home/sm26363/Mercurial/Mercurial/qex1/.hg/incoming
applying Makefile
applying fix1
applying message
applying bye
now at: bye
$ 
$ hg glog --template "{rev}:{node|short} {author|user}\n{desc|firstline}\n\n" 
@    11:8db2598210ab Stacey
|\   imported patch bye
| |
| o    10:2d966b806fb1 Stacey
| |\   Fix world
| | |
| | o    9:e63a43ac5532 Stacey
| | |\   remove implicit function declaration warnings
| | | |
| | | o    8:a1205da4671a Stacey
| | | |\   imported patch Makefile
| | | | |
| | | | o  7:3f838495d0e4 Stacey
| | | | |  [mq]: merge marker
| | | | |
| | | | o  6:2048a9e0068b beginner
| | | | |  Added README for support.
| | | | |
+---------o  5:db6e2d5b6aa2 Stacey
| | | | |    hg patches saved state
| | | | |
o | | | |  4:cdb5958dcd87 Stacey
|/ / / /   imported patch bye
| | | |
o | | |  3:d20726d3cc4d Stacey
|/ / /   Fix world
| | |
o | |  2:63144e5ebe68 Stacey
|/ /   remove implicit function declaration warnings
| |
o |  1:be53b09aed16 Stacey
|/   [mq]: Makefile
|
o  0:390c5f52f8e3 beginner
   First program

As the fictional character Ford Prefect would say, “Don't Panic!”. That is what we were expecting. We're safe now to pop the patches off, stay with it:

$ hg qpop -a
patch queue now empty
$ hg glog --template "{rev}:{node|short} {author|user}\n{desc|firstline}\n\n"
@  6:2048a9e0068b beginner
|  Added README for support.
|
| o  5:db6e2d5b6aa2 Stacey
| |  hg patches saved state
| |
| o  4:cdb5958dcd87 Stacey
| |  imported patch bye
| |
| o  3:d20726d3cc4d Stacey
| |  Fix world
| |
| o  2:63144e5ebe68 Stacey
| |  remove implicit function declaration warnings
| |
| o  1:be53b09aed16 Stacey
|/   [mq]: Makefile
|
o  0:390c5f52f8e3 beginner
   First program

$ hg qpop -a -n incoming
using patch queue: /export/home/sm26363/Mercurial/Mercurial/qex1/.hg/incoming
saving bundle to /export/home/sm26363/Mercurial/Mercurial/qex1/.hg/strip-backup/be53b09aed16-temp
adding branch
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
patch queue now empty
$ hg qseries -v
0 U Makefile
1 U fix1
2 U message
3 U bye
$ hg qlog
@  changeset:   1:2048a9e0068b
|  tag:         tip
|  user:        beginner
|  date:        Tue Oct 27 21:17:05 2009 +0000
|  summary:     Added README for support.
|
o  changeset:   0:390c5f52f8e3
   user:        beginner
   date:        Tue Oct 27 21:17:02 2009 +0000
   summary:     First program

The above shows the incoming changeset and our patches un-applied. The patches may now be re-applied:


$ hg qpush -a
applying Makefile
applying fix1
applying message
applying bye
now at: bye
$ hg qlog
@  changeset:   5:a19f79097ba6
|  tag:         qtip
|  tag:         tip
|  tag:         bye
|  user:        Stacey Marshall ‹Stacey.Marshall@Sun-DOT-COM›
|  date:        Tue Oct 27 21:17:07 2009 +0000
|  summary:     imported patch bye
|
o  changeset:   4:74fc52a79383
|  tag:         message
|  user:        Stacey Marshall ‹Stacey.Marshall@Sun-DOT-COM›
|  date:        Tue Oct 27 21:17:07 2009 +0000
|  summary:     Fix world
|
o  changeset:   3:63ca0f087340
|  tag:         fix1
|  user:        Stacey Marshall ‹Stacey.Marshall@Sun-DOT-COM›
|  date:        Tue Oct 27 21:17:07 2009 +0000
|  summary:     remove implicit function declaration warnings
|
o  changeset:   2:c601487f5539
|  tag:         Makefile
|  tag:         qbase
|  user:        Stacey Marshall ‹Stacey.Marshall@Sun-DOT-COM›
|  date:        Tue Oct 27 21:17:07 2009 +0000
|  summary:     imported patch Makefile
|
o  changeset:   1:2048a9e0068b
|  tag:         qparent
|  user:        beginner
|  date:        Tue Oct 27 21:17:05 2009 +0000
|  summary:     Added README for support.
|
o  changeset:   0:390c5f52f8e3
   user:        beginner
   date:        Tue Oct 27 21:17:02 2009 +0000
   summary:     First program

Preparing to push

The final step is to remove the queues, as with those intact we're unable to push. To accomplish this use qfinish But before we clear the queues take a backup of them using qcommit and clone as its likely we'll have to pull again as we raise to push.

Note: Simply doing a qcommit is not sufficient because qfinish tidies up the patches, a peek into the working files shows this best - I've avoided showing these details previously:

$ hg qcommit -m "pre-finish"
$ ls .hg/patches
bye       fix1      Makefile  message   series    status
$ hg qfinish -a
patch Makefile finalized without changeset message
patch bye finalized without changeset message
$ ls .hg/patches
series  status
$ 

By cloning the patches before qfinish we can then recover them after stripping off our patched changesets, Lets look at another example.

$ hg qcommit -m 'Pre-finish'
$ hg clone .hg/patches .hg/patches-backup
updating working directory
6 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg qpush -a
all patches are currently applied
$ hg qfinish -a
patch Makefile finalized without changeset message
patch bye finalized without changeset message
$ 

Now lets assume there is something to pull, we'll have to remove our outgoing changes using strip:

$ hg outgoing
comparing with /export/home/sm26363/Mercurial/Mercurial/qexample
searching for changes
changeset:   2:c601487f5539
user:        Stacey Marshall ‹Stacey.Marshall@Sun-DOT-COM›
date:        Tue Oct 27 21:17:07 2009 +0000
summary:     imported patch Makefile

changeset:   3:63ca0f087340
user:        Stacey Marshall ‹Stacey.Marshall@Sun-DOT-COM›
date:        Tue Oct 27 21:17:07 2009 +0000
summary:     remove implicit function declaration warnings

changeset:   4:74fc52a79383
user:        Stacey Marshall ‹Stacey.Marshall@Sun-DOT-COM›
date:        Tue Oct 27 21:17:07 2009 +0000
summary:     Fix world

changeset:   5:a19f79097ba6
tag:         tip
user:        Stacey Marshall ‹Stacey.Marshall@Sun-DOT-COM›
date:        Tue Oct 27 21:17:07 2009 +0000
summary:     imported patch bye

$ hg strip 2
2 files updated, 0 files merged, 1 files removed, 0 files unresolved
saving bundle to /export/home/sm26363/Mercurial/Mercurial/qex1/.hg/strip-backup/59b69da7d392-backup
$ hg log
changeset:   1:2048a9e0068b
tag:         tip
user:        beginner
date:        Tue Oct 27 21:17:05 2009 +0000
summary:     Added README for support.

changeset:   0:390c5f52f8e3
user:        beginner
date:        Tue Oct 27 21:17:02 2009 +0000
summary:     First program

$ 

Recover the backups:

$ rm -rf .hg/patches 
$ hg clone .hg/patches-backup .hg/patches
updating working directory
6 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg qseries -v
0 U Makefile
1 U fix1
2 U message
3 U bye
$ 

So there we have it, we can then check the incoming, if it touches anything we've edited then we can go through the merge operation above and or pull, update re-apply patches, finish and patch.

Changing changeset message

As seen above qfinish nicely told us that some changesets were missing messages. These can be applied using qrefresh -m:

$ hg qseries -v
0 U Makefile
1 U fix1
2 U message
3 U bye
$ hg qpush Makefile
applying Makefile
now at: Makefile
$ hg qrefresh -m "Makefile changes"
$ hg qpush bye
applying fix1
applying message
applying bye
now at: bye
$ hg qrefresh -m "Bye: says goodbye"
$ hg glog
@  changeset:   5:202431aaf294
|  tag:         qtip
|  tag:         tip
|  tag:         bye
|  user:        Stacey Marshall ‹Stacey.Marshall@Sun-DOT-COM›
|  date:        Tue Oct 27 22:45:47 2009 +0000
|  summary:     Bye: says goodbye
|
o  changeset:   4:7494b600f084
|  tag:         message
|  user:        Stacey Marshall ‹Stacey.Marshall@Sun-DOT-COM›
|  date:        Tue Oct 27 22:45:21 2009 +0000
|  summary:     Fix world
|
o  changeset:   3:69c047974d13
|  tag:         fix1
|  user:        Stacey Marshall ‹Stacey.Marshall@Sun-DOT-COM›
|  date:        Tue Oct 27 22:45:21 2009 +0000
|  summary:     remove implicit function declaration warnings
|
o  changeset:   2:439652f08146
|  tag:         Makefile
|  tag:         qbase
|  user:        Stacey Marshall ‹Stacey.Marshall@Sun-DOT-COM›
|  date:        Tue Oct 27 22:45:15 2009 +0000
|  summary:     Makefile changes
|
o  changeset:   1:2048a9e0068b
|  tag:         qparent
|  user:        beginner
|  date:        Tue Oct 27 21:17:05 2009 +0000
|  summary:     Added README for support.
|
o  changeset:   0:390c5f52f8e3
   user:        beginner
   date:        Tue Oct 27 21:17:02 2009 +0000
   summary:     First program

Note: Obviously for OpenSolaris repository the messages must follow the bug-id synopsis format.

References

  1. Mq Tutorial
  2. Merging Patches
  3. Multiple changeset pushes to ON - utilising ZFS snapshots for rollback

Last but not least, hg help mq.

Stace

Monday Dec 15, 2008

In my day-to-day role as a software engineer I share with my peers unified-differences derived from the diff(1) command. For example:


$ diff -u old new
  --- old	Wed Oct 29 14:36:47 2008
+++ new	Wed Oct 29 14:36:56 2008
@@ -1,9 +1,15 @@
 I
 really
-should
+ought
 provide
 better
 examples.
 
-Or at least use some of my daughters poetry
+Mary
+had
+a
+little 
+lamb,
+
+Or perhaps use some of my daughters poetry.

$

Where differences occur a line listing the original line number followed by the new line numbers are displayed which is followed by the changes. Lines removed from "new" are marked with a "-" at the beginning while lines added to "new" are marked with a "+". In the example its quite easy to see that line three has been removed and replaced. However it is sometimes not so obvious, the line numbers get a little confusing in ensuing conversation.

So I put together a little nawk script to display the line numbers in-line as well:

$ diff -u old new | udiffn
--- old	Wed Oct 29 14:36:47 2008
+++ new	Wed Oct 29 14:36:56 2008
 Old  New @@ -1,9 +1,15 @@
   1    1  I
   2    2  really
   3      -should
        3 +ought
   4    4  provide
   5    5  better
   6    6  examples.
   7    7  
   8      -Or at least use some of my daughters poetry
        8 +Mary
        9 +had
       10 +a
       11 +little 
       12 +lamb,
       13 +
       14 +Or perhaps use some of my daughters poetry.
   9   15  

Ideally diff(1) would have an option to provide this output but in the mean time this little tool will suffice:

$ cat ~/tools/sh/udiffn
#!/bin/nawk -f
# Add line numbers to unified diff output: diff -u old new | udiffn
/^No differences encountered/ ||		# No exit as intended as a pipe
/^$/ ||						# Blank lines
/^(\-\-\-|\+\+\+)/ {print; next;}		# diff Headers
/^@@ [-+][0-9]*,[0-9]* [+-][0-9]*,[0-9]* @@/ {	# Start of difference block
  i=split(substr($2,2), o, ",");		# old start line in o[1]
  j=split(substr($3,2), n, ",");		# new start line in n[1]
  l=length(n[1])+1;				# Numeric field length
  if (l <= 4 ) l = 4;
  printf("%*s %*s %s\n", l, "Old", l, "New", $0);
  next;
}

/^ /	{printf("%*s %*d %s\n", l, o[1]++, l, n[1]++, $0); next;}
/^\+/	{printf("%*s %*d %s\n", l, " ", l, n[1]++, $0); next;}
/^\-/	{printf("%*d %*s %s\n", l, o[1]++, l, " ", $0); next;}

/^Index: / {print; next}			# patch/wx header
/^diff -r/ {print; next}			# Mercurial header
# Everything else is unexpected.
{print "Er!",NR,$0;}

Friday Nov 14, 2008

I've just found out that it is possible to select Point-to-focus, my preferred focus policy, on Windows XP. I found the option in Tweak UI which can be down loaded from the MS Power Toys for Windows XP page. To enable Point-to-Focus run Tweak UI, navigate down the right pane to Mouse -> X-Mouse and select "Activation follows mouse (X-Mouse)". As of yet I have not found an option to stop raising the window on click!

I came across Tweak UI utility as having purchased a new 1TB disc I wanted to move the common "Shared" folders to it. I tried dragging the folder as suggested but this didn't seem to have the desired effect. Some goolge time later I found Tweak UI which also has an option to change those settings. Looks like there are some other useful tools in there too, such as CmdHere and DeskMan.

Thursday Mar 02, 2006

As you may recal I have been trying out JDS and so thought I would give Evolution a spin. My first experiance was not too bad, though I have come to use Thunderbird's short-cut keys which are of course different to Evolution's. One thing I noticed with evolution was that I could use my PGP key to sign my email. I recalled that Chris's e-mail was digitally signed and sure enough found that he blogged the process. I thus now have a digital signature to my office emails and can look forward to people asking me "what's that?"

On the subject of email, my youngist daughter has the word 'email' in her spellaphon, which is why I am using email rather than e-mail!

Stace

Wednesday Mar 01, 2006

FreeMind is project of the month on SourceForge. FreeMind is a very simple to use mind-mapping program, or a tree editor. One of my favourite features is that it can be almost fully controlled via the keyboard. I see that their is also a PDA application FreeMindPDA which is able to read and write FreeMind's XML files. The PDA version is a rewrite using SuperWaba, an open-source software development platform for PDAs.

Friday Feb 24, 2006

Just a quick blog to mention auto-completion in XEmacs.

Auto Completion is a very helpful feature when entering the same name over and over again. Such as complicated variable names or identifying numbers. Though it can be used for any word (alpha numeric string),

Firstly, to use completion enable it by adding the following to your .emacs file and evaluate it (C-x C-e):

(require 'completion) 

After you type a few characters, pressing the “complete” (meta-return) key inserts the rest of the word you are likely to type. Consecutive presses rotate through all possibilities. If you like the completion then just continue typing, it is as if you entered the text by hand. If you want the inserted extra characters to go away, type control-w or delete.

The guesses are made in the order of the most recently “used”. Typing in a word and then typing a separator character (such as a space) “uses” the word. So does moving a cursor over the word. If no words are found, it uses an extended version of the dabbrev style completion.

For further information refer to the text at the beginning of /opt/sfw/lib/xemacs/xemacs-packages/lisp/edit-utils/completion.el

Stace

Wednesday Oct 05, 2005

I'm reviewing some ksh fixes with XEmacs and my cursor is sat on a closing curly brace. I can see that brace completes function 'item' from the status bar, but I want to get from this closing brace to the opening brace as quickly as possible...

M-C-b (escape control b) invokes backward-sexp which documents itself as “Move backward across one balanced expression (sexp)”.

M-C-f (escape control f) invokes forward-sexp which does the opposite.

Summary of sexp key combinations are:

M-C-b		backward-sexp
M-C-f		forward-sexp
M-C-@		mark-sexp
M-C-k		kill-sexp
M-C-t		transpose-sexps
M-C-backspace	backward-kill-sexp
M-C-delete	backward-or-forward-kill-sexp
M-C-space	mark-sexp
C-x C-e		eval-last-sexp
M-C-q		indent-sexp

Stace

Updated 1 Mar 2006 to show complete list above; to see the list in XEmacs c-mode use 'C-h M-x occur sexp'.

Tag:

This blog copyright 2009 by ace