If you are a windows user and want emacs to appear in the context menu, here's one way to do that. It involves tinkering with the registry and it creates a new instance of Emacs on every file you use it on.
Postings on living in an Emacs world. Posts will be mostly on using Emacs, related functions and tools.
Ads by Google
Thursday, July 10, 2008
Monday, July 7, 2008
Learning to use the Emacs keyboard macro system effectively
The Emacs macro system is probably the least used feature by newbies and intermediate users. Which is a shame as it's a really neat piece of code and the learning overhead is very small.
The latest versions of Emacs has the keys F3 and F4 mapped to start and end of the macro recording. And the next invocation of F4, runs the last created macro.
Recording a macro is easy. Hit F3 and start working. Of course, the idea of a macro is to do repetitive tasks and one needs to record the steps and apply it to the buffer text.
Here's where it is important to get things right.
One,don't worry about efficiency or the least number of keystrokes to achieve the task. Most times, the macros are one off and will rarely be suitable for another task later in the day or week. I've rarely had the chance to reuse any of the macros I've written. And every piece of "similar" text you receive, the odds are better that you do the macro from scratch again.
Second, use the emacs provided line commands instead of counting words, letters and spaces. Your macro is more robust if it is recorded in emacs contextual fragments i.e
C-a
C-e
M-f
M-e
C-n
C-j
etc.
Counting characters instead of using Emacs word boundary definition will lead you astray. Your macro will work for some cases and break in case of the others.
Three, once you get the hang of this, you can edit the macro by M-x edit-last-kbd-macro and delete/add additional corrections you want, and make it available by hitting C-c C-c to recompile the macro.
Try it on a couple of lines of text by hitting F4 and see where the point ends. That typically will tell you what happens if the results are not what you expected when you run the macro. You might have to add a C-n or C-j to move or create a newline.
Once you get the hang of simple macros, you can then move on to more difficult versions of the same. I've once used macros to copy stuff across 2 buffers back and forth. The more you use macros, the more natural it will be to use it for any and every repetitive tasks.
You'll find it really useful when editing UNIX shell scripts, data files and configuration files
The latest versions of Emacs has the keys F3 and F4 mapped to start and end of the macro recording. And the next invocation of F4, runs the last created macro.
Recording a macro is easy. Hit F3 and start working. Of course, the idea of a macro is to do repetitive tasks and one needs to record the steps and apply it to the buffer text.
Here's where it is important to get things right.
One,don't worry about efficiency or the least number of keystrokes to achieve the task. Most times, the macros are one off and will rarely be suitable for another task later in the day or week. I've rarely had the chance to reuse any of the macros I've written. And every piece of "similar" text you receive, the odds are better that you do the macro from scratch again.
Second, use the emacs provided line commands instead of counting words, letters and spaces. Your macro is more robust if it is recorded in emacs contextual fragments i.e
C-a
C-e
M-f
M-e
C-n
C-j
etc.
Counting characters instead of using Emacs word boundary definition will lead you astray. Your macro will work for some cases and break in case of the others.
Three, once you get the hang of this, you can edit the macro by M-x edit-last-kbd-macro and delete/add additional corrections you want, and make it available by hitting C-c C-c to recompile the macro.
Try it on a couple of lines of text by hitting F4 and see where the point ends. That typically will tell you what happens if the results are not what you expected when you run the macro. You might have to add a C-n or C-j to move or create a newline.
Once you get the hang of simple macros, you can then move on to more difficult versions of the same. I've once used macros to copy stuff across 2 buffers back and forth. The more you use macros, the more natural it will be to use it for any and every repetitive tasks.
You'll find it really useful when editing UNIX shell scripts, data files and configuration files
Friday, July 4, 2008
Quickly Creating LaTeX Tables in Emacs
One of the "that sucks" part of using LaTeX is the part about creating tables. While it is powerful, the idea of all those ampersands, slashes and \hlines makes me go ape. And it takes a couple of edit-compile-view cycles to get into the groove of table writing in LaTeX.
Thankfully Emacs has the table mode as part of the standard distribution. Invoke table-mode as M-x table-insert and create the table. Answer the wizard questions and enter the data for the columns. Once you've written the data into the table, generate the LaTeX table by hitting C-^ and choosing the export format as latex.
Done.
Paste that back into your tex file and add the \usepackage{tabular} or \usepackage{tabularx} to the preamble and compile the file. Adjust the spacing by deleting off unwanted table rows.
This beats the earlier method by a large order in terms of productivity if you can't be bothered to learn LaTeX tables.
And one other tip: Create the emacs table in the tex file and comment it out. If you ever want to make extensive changes to the table, do the following.
Thankfully Emacs has the table mode as part of the standard distribution. Invoke table-mode as M-x table-insert and create the table. Answer the wizard questions and enter the data for the columns. Once you've written the data into the table, generate the LaTeX table by hitting C-^ and choosing the export format as latex.
Done.
Paste that back into your tex file and add the \usepackage{tabular} or \usepackage{tabularx} to the preamble and compile the file. Adjust the spacing by deleting off unwanted table rows.
This beats the earlier method by a large order in terms of productivity if you can't be bothered to learn LaTeX tables.
And one other tip: Create the emacs table in the tex file and comment it out. If you ever want to make extensive changes to the table, do the following.
- Uncomment the emacs table
- Move point to the table or highlight the region
- M-x table-recognize will make it ready to edited as an emacs table
- make the changes and export it again as latex
- comment out the emacs table
Tuesday, July 1, 2008
Jumping to specific line in a buffer
Well, with the previous versions of emacs one had to map the goto-line to some key like C-z; now you can save that binding and hit M-g g to get prompted for the line number.
How good a binding is that? I leave that to you to decide.
How good a binding is that? I leave that to you to decide.
Saturday, June 28, 2008
What font is the text in the current buffer?
To know what the font and what the glyph codes are, use C-u C-x = on the current character the point is on. You should see something like
character: i (105, #o151, #x69, U+0069)
charset: ascii (ASCII (ISO646 IRV))
code point: #x69
syntax: w which means: word
category: a:ASCII graphic characters 32-126 (ISO646 IRV:1983[4/0]) l:Latin
buffer code: #x69
file code: #x69 (encoded by coding system windows-1252-unix)
display: by this font (glyph code)
-outline-DejaVu Sans Mono-normal-r-normal-normal-16-120-96-96-c-*-iso8859-1 (#x69)
It can also be invoked as M-x describe-char.
character: i (105, #o151, #x69, U+0069)
charset: ascii (ASCII (ISO646 IRV))
code point: #x69
syntax: w which means: word
category: a:ASCII graphic characters 32-126 (ISO646 IRV:1983[4/0]) l:Latin
buffer code: #x69
file code: #x69 (encoded by coding system windows-1252-unix)
display: by this font (glyph code)
-outline-DejaVu Sans Mono-normal-r-normal-normal-16-120-96-96-c-*-iso8859-1 (#x69)
It can also be invoked as M-x describe-char.
Wednesday, June 25, 2008
pgfplots: Plotting in LaTeX
pgfplots looks like a promising package for getting plots into LaTeX. I should probably give it a spin. The manuals, in PDF, here and here are detailed and extensive. And the plots are lovely; beautiful. (There, I get all nerdy)
One reason that I'd like to learn this package is that the alternate approach is to use gnuplot to generate a jpeg and then include that into LaTeX file. That comes with a whole bunch of issues like fiddling with fonts to match the LaTeX font scheme one uses, scaling the jpeg image to fit page and colours.
Since pgfplots is another package with the TeX system, it should be technically be a case of simpler and smaller dependencies for plots. And it uses the same pgf package that is part of the larger beamer package developed by Till Tantau. If you're a MikTeX user, it is available as a download from the package manager.
One reason that I'd like to learn this package is that the alternate approach is to use gnuplot to generate a jpeg and then include that into LaTeX file. That comes with a whole bunch of issues like fiddling with fonts to match the LaTeX font scheme one uses, scaling the jpeg image to fit page and colours.
Since pgfplots is another package with the TeX system, it should be technically be a case of simpler and smaller dependencies for plots. And it uses the same pgf package that is part of the larger beamer package developed by Till Tantau. If you're a MikTeX user, it is available as a download from the package manager.
Saturday, June 21, 2008
Common Emacs lisp idioms
This page by Xah Lee might be useful if you're into elisp programming.
Wednesday, June 18, 2008
Changing the default mode of the *Scratch* buffer
The default *Scratch* buffer in Emacs starts in fundamental mode which might not be useful for lots of people who either don't know or want to work on elisp.
If text mode makes sense for you as the default, the following addition to the .emacs file should fix it.
(setq initial-major-mode 'text-mode)
Note that you don't lose much if you're trying out a few lisp forms as they can be eval'ed anywhere by hitting C-x C-e that would have the same effect as doing it in lisp mode.
If text mode makes sense for you as the default, the following addition to the .emacs file should fix it.
(setq initial-major-mode 'text-mode)
Note that you don't lose much if you're trying out a few lisp forms as they can be eval'ed anywhere by hitting C-x C-e that would have the same effect as doing it in lisp mode.
Sunday, June 15, 2008
Creating animations in PDF using LaTeX
If you ever wanted to simple animations of your graphs or pictures in your LaTeX paper then the animate package is the way to go. The documentation and examples are good to get you started.
Wednesday, June 11, 2008
A quick way to open files in Emacs
Emacs users when interacting with the shell have a faster method to open files compared to other editors. Most editors will provide a shell escape through which a listing of a directory can be got; or a find command executed.
That's it.
You still need to highlight the interested file, copy into your "open file" dialog and then open the file. Well, Emacs offers the same feature too and more.
If your point is positioned at the start of the file name /tmp/foo, then M-x ffap which stands "find file at point" opens the file. As usual the excellent documentation of ffap gives you other options. Apart from the name, the way the file is opened is simply intuitive without any fuss. In fact, the documentation lists other options to ffap that might useful for mouse users.
That's it.
You still need to highlight the interested file, copy into your "open file" dialog and then open the file. Well, Emacs offers the same feature too and more.
If your point is positioned at the start of the file name /tmp/foo, then M-x ffap which stands "find file at point" opens the file. As usual the excellent documentation of ffap gives you other options. Apart from the name, the way the file is opened is simply intuitive without any fuss. In fact, the documentation lists other options to ffap that might useful for mouse users.
Subscribe to:
Posts (Atom)