Xah Emacs Blog Archive 2012-07

Ask Emacs Tuesday.

My elisp tutorial has been mentioned on Hacker News. http://news.ycombinator.com/item?id=4309527

Thank you “jackhammer2022” for posting it, and all supporters, on twitter, Google Plus, email, and all those who have donated or bought my tutorial!

There's also some negative comments on Hacker News. If you like them answered, let me know! (comment, or post to Google Plus, twitter, fb.)

New page and update: Elisp: Get User Input.

Emacs as Your Own IDE

wanted to share this with everyone.

with emacs, you pretty much develop your own IDE, especially if you do elisp. After a few years in your coding career, you'll have a IDE of your own that's far better than any.

the downside is that you have to learn elisp. But gradually, like a couple hours a week. You'll do that anyway if you love coding. Without emacs, programers usually accumulate a bunch of shell scripts over the years, or in python, perl, scsh. But with elisp, it's integrated in the editor!

Ask Emacs Tuesday.

Make Emacs Always Start a New Shell

In GNU Emacs, to start a second shell interface, Alt+x shell by first typing 【Ctrl+u】.

[Ellen Taylor https://plus.google.com/b/113859563190964307534/118418624395898188790/posts] provided the following code, which makes shell command always start a new shell.

;; by Ellen Taylor, 2012-07-20
(defadvice shell (around always-new-shell)
  "Always start a new shell."
  (let ((buffer (generate-new-buffer-name "*shell*"))) ad-do-it))

(ad-activate 'shell)

See also: Emacs: Run Shell in Emacs.

updated: Emacs: Edit Column Text, Rectangle Commands

Emacs: Using Registers (Multiple Clipboards)

Updated: Emacs: Save Split Windows Configuration

Curiosity: Perl File Extension in Emacs Config

A curiosity question.

emacs's “auto-mode-alist” has this value:

("\\.\\([pP]\\([Llm]\\|erl\\|od\\)\\|al\\)\\'" . perl-mode)

the regex there seems a bit wild. If i didn't get it wrong, then its like this

. ([pP] ( [Llm] | erl | od ) | al )

so it covers:

.pl
.perl
.pod
.pm
.al

plus SOME case variations. For example: {.pL , .PL}.

what's the “.al” for?

is it necessary to include the “.pod”? because the perl-mode doesn't do any coloring with “.pod” files, nor cperl-mode. If there's a mode handing “.pod” file am guessing it won't be perl-mode.

also, is the “.perl” there necessary? Is that a accepted perl file suffix? (Just checked it's not in any file bundled with perl v5.10.1.)

would it be better if it's just

("\\.\\(p\\([lm]\\)\\)\\'" . perl-mode)

?

John Bokma answers: the “.al” is used for http://perldoc.perl.org/AutoLoader.html.

Elisp: Getting Current Buffer Path

In your elisp program, you may call (buffer-file-name) to get the full path of the file, but sometimes the current buffer isn't associated with a file, so your program will fail.

Here's a idiom: (or (buffer-file-name) default-directory). This way, if the buffer isn't a file, it'll return the directory path of the buffer. (when a buffer is created, its “default-directory” is typically the same as previous buffer. In the case of temp buffers created by emacs such as {*info*, *scratch*, *Bookmark List*, …}, it's usually home dir.)

I just searched all my elisp files for this oversight.

Elisp: Ways to Exit/Break a Loop

List of Keyboards with Mechanical Switch

Emacs: Ways to Jump to Points

when coding, there's a common need to jump to a particular place, then return to previous position.

There are several ways. Most common standard methods are:

I've tried all ways in past years, including custom elisp that push/pop marks. But i found split windows to be the best.

Split window, then go to where you wanna be, when done, unsplit. Give split/unsplit a easy key. [see Emacs: How to Define Keys] For example, in ErgoEmacs, it's:

On a different note, here's a nice tip when using mouse (thx to Ken Goldman):

Elisp: Adding Your Package to MELPA

Emacs 24's package system is hot. It spreads a few hundred packages to every emacs user. (In GNU emacs, 41 packages (not counting built-in ones). With MELPA, 307 packages.) Before this, it takes years of emacs experience to know what packages are out there that are actually usable.

So, if you have written a package, putting it into a package repository would greatly increase your user base. I haven't done it yet myself, but here's a summary from [Jon-Michael Deldin https://plus.google.com/b/113859563190964307534/109772184528326404914/posts].

MELPA is pretty easy (https://github.com/milkypostman/melpa#contributing-new-packages) after you do it once.

  1. Fork the MELPA repository on GitHub
  2. Create a new file in the “recipes” directory with the right format. It's really easy — just take a look at an example recipe (https://github.com/milkypostman/melpa/blob/master/recipes/ir-black-theme).
  3. Test it with the ./buildpkg script and do M-x package-install-file
  4. On GitHub, visit your fork and click the Pull Request button

That's pretty much it. Marmalade is a little easier (just upload a tar or .el), but you have to upload a new version for each release.

slight update: Emacs: Bookmark Tutorial

Lisp Syntax Readable?

See bottom: Concepts and Confusions of Prefix, Infix, Postfix and Lisp Notations.

Emacs Key Macro and Elisp Exercise: Reformat XML

2012-07-02, Mihamina Rakotomandimby posted a interesting problem (Source groups.google.com):

I got a big one line XML file. I want to break the lines to make it more readable.

Replacing "><" with "C-j" then indenting is the most obvious solution, but would you know a more elegant solution?

This is a good exercise for writing a emacs keyboard macro. Record a key macro, save it, assign it a key. So, just press one key, and the file is indented and well-formatted.

to indent, just select all then call indent-regionCtrl+Alt+\】.

For key macro tutorial, see: Emacs: Keyboard Macro.

or, if you are a emacs expert but never done any elisp, this is a great exercise. Write a command that does this. It's about 5 lines of elisp. [see Emacs Lisp Examples]

Emacs Defect. GNU Emacs 24.1.1: global-set-key to Insert French Quotation Mark. Archived at Emacs Misc Bugs

updated: Emacs: How to Install Packages Using ELPA, MELPA

Updated: Elisp: Command to Extract URL

Copy/Paste in Linux X11 and Emacs 24

See: Emacs 24.1 New Features (released 2012-06)

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs

Emacs

Emacs Lisp

Misc