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, g+, email, and all those who have 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 g+, twitter, fb.)
New page and update: Emacs Lisp Idioms: Prompting for 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!
Make Emacs Always Start a New Shell
In GNU Emacs, to start a second shell interface, call shell by first typing 【Ctrl+u】.
Ellen Taylor 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 Shell Tutorial (Bash, cmd.exe, PowerShell).
updated: Emacs: Manipulate Column Text, Align Decimal, ASCII-Art
Emacs: Using Registers (Multiple Clipboards)
Updated: Emacs: Manage Split Windows
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. ⁖ {.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.
Emacs Lisp: 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.
Emacs Lisp: 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:
exchange-point-and-mark 【Ctrl+x Ctrl+x】.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. 〔☛ Emacs: How to Define Keys〕 ⁖ In ErgoEmacs, it's:
delete-other-windowssplit-window-verticallydelete-windowother-windowOn a different note, here's a nice tip when using mouse (thx to Ken Goldman):
Emacs Lisp: 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 summery from Jon-Michael Deldin.
MELPA is pretty easy (https://github.com/milkypostman/melpa#contributing-new-packages) after you do it once.
- Fork the MELPA repository on GitHub
- 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).
- Test it with the ./buildpkg script and do M-x package-install-file
- 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: Using Emacs's Bookmark Feature
Lisp Syntax Readable?
See bottom: Concepts & Confusions of {Prefix, Infix, Postfix, Fully Nested} 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-region 【Ctrl+Alt+\】.
For key macro tutorial, see: Emacs: Using Keyboard Macro to Record/Playback Keystrokes.
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. 〔☛ Emacs Lisp Examples ₁〕
Emacs Defect. GNU Emacs 24.1.1: global-set-key to Insert French Quotation Mark. Archived at Emacs Misc Bugs
updated: A Guide on Emacs 24 Package System
Updated: Emacs Lisp: Writing a Command to Extract URL
Copy/Paste in Linux X11 and Emacs 24
blog comments powered by Disqus