Xah Emacs Blog Archive 2012-12

wrote this today. Emacs Lisp: HTML, Update Title

New. Intro to Emacs Lisp Symbol. Lisp experts, comment and correction welcome.

Emacs Lisp: Check if a {function, variable, feature} is Defined/Loaded

emacs lisp: update timestamp

wrote this today.

(defun xah-update-article-timestamp ()
  "Update article's timestamp.
Add today's date to the form
 <p class=\"author_0\">Xah Lee, <time>2005-01-17</time>, <time>2011-07-25</time></p>
 of current file."
  (interactive)
  (let (p1 p2)
    (save-excursion
      (goto-char (point-min))
      (when (search-forward "<p class=\"author_0\">Xah Lee" nil)
        (beginning-of-line)
        (setq p1 (point) )
        (end-of-line)
        (setq p2 (point) )
        (search-backward "</p>")
        (insert (format ", <time>%s</time>" (format-time-string "%Y-%m-%d"))
                ) ) ) ))

press a button, then current page's date stamp is updated. This command saves me about 30 keystrokes and error-prone manual process.

you might modify this to update your blog, code, org-mode file, for similar purpose.

the point of this post is not about a trick to auto-update timestamp, but rather, the usefulness of little emacs lisp code, that can update anything uniquely identifiable in current file (or even another file.)

Keyboard Shortcut Design: Repeatable vs Non-Repeatable Commands and Keys

Here's a command that does letter case change. It merges emacs 6 commands. Emacs: Letter-Case Commands Usability Problems. (in ErgoEmacs keybinding, it's set to Alt+/ on QWERTY position.)

Emacs Lisp: Syntax Color Source Code

recently, rewrote several elisp code for syntax color source code in HTML. This is real convenient if you write blogs and often have computer language source code. For example, if you have:

<pre class="python">
…
print 5
…
</pre>

This is similar to how you can execute code in org-mode.

For elisp tutorial, see: Emacs Lisp: Syntax Color Source Code in HTML. Link to the new code at bottom on github.

There's lots more ErgoEmacs keybinding update on MELPA. All thanks to a true elisp expert Matthew L Fidler https://github.com/mattfidler

I won't be announcing more changes about ErgoEmacs for now, just check MELPA regularly. If you have any questions, post to https://groups.google.com/group/ergoemacs or file a bug at http://code.google.com/p/ergoemacs/issues/list

updated: Unicode in Ruby, Perl, Python, JavaScript, Java, Emacs Lisp, Mathematica

I've been writing emacs tutorial for about 6 years. I started using emacs daily in 1998. Then, around 2005 i joined emacs irc channel, and learned a whole lots of things i thought i knew. I started to write notes to myself, then some tips are really useful that i felt others would benefit. One of the first such tutorial is Emacs: Unicode Tutorial. In the past 3 years or so, i've been working on the tutorial about 3 hours a day. When i get a praise, it brightens my day, especially from experienced emacs users.

I got this hearty one today.

Thank YOU for your fantastic resource. I've been an emacs user for 28 years, and I've learned countless things from your tutorials.

If you like my tutorial, read it, subscribe, tell friends, or Buy it please. That'd give me much incentive to make it better. Thank you.

Emacs: Backup Current File 🚀

I just sent out download link to my emacs tutorial. If you bought it before but didn't receive the email, please email me Xah@XahLee.org and say “emacs tutorial update”. I'll email it to you and put you on the mailing list. Thank you.

Also, i just got one person's payment but the email to him bounced. Be sure your email is correct, else i have no way to contact you. Email me please.

A new version of my tutorial is available. See: Buy Xah Emacs Tutorial.

I'll be sending out the download link to those who bought it before. Thanks.

Annoying Invisible ZERO WIDTH NO-BREAK SPACE Character from Google Plus, Twitter and how to use elisp to solve it.

Emacs: iswitch vs ido mode

Question to Readers: {Perl, Python, Ruby}, Together on One Page, or Separate?

I have

There, each page, has both languages for comparative study.

My question is, should i also put my new Ruby Tutorial there for comparative study? Or, should Ruby by itself?

I can actually also put {Emacs Lisp, PHP} there for comparative study too. But then each page will be long. Alternatively, if each language is on separate page, with inter-links, then people could page between any two languages.

Which way do you prefer?

Again, the ErgoEmacs keybinding package has been updated a lot. By Matthew L Fidler (https://github.com/mattfidler). Most of the codes are by Matthew and David Capello [https://davidcapello.com/].

I updated the home page a bit to reflect current status. ErgoEmacs Keybinding.

IMPORTANT: Note: in the dev version, the isearch is moved from Alt+; to Alt+y. Cancel command is moved from Alt+n to Escape. (here, using QWERTY notation)

moving emacs dot files into ~/.emacs.d/ started in emacs 23, but it didn't catch all. Emacs 24 moved more, but still some left. As of now, i still see these (some are created 3rd party elisp packages):

.emacs-bmk-bmenu-state.el
.emacs-places
.ido.last
.recentf
.smex-items

moved into its own page: Emacs: Convert Chinese/Japanese Full-Width/Half-Width Punctuations 🚀

moved into its own page: Emacs: rainbow-delimiters-mode, Customize Bracket Color

emacs: sorting multiple fields

sudhir_godbole wrote:

Is there a way in emacs to sort with a primary field and then a secondary field. I remember Linux command sort having one such option.

You call sort-fields or sort-numeric-fields multiple times. But you could call unix sort with text selection as input and replace selection. Alt+x shell-command-on-regionCtrl+u Alt+|】.

Is there a better way to sort by multiple fields in one shot?

emacs Google Plus Community

[Andrew Hyatt https://plus.google.com/101505495157778834572/posts], a Google engineer, and heavy emacs user, author of emacs-websocket https://github.com/ahyatt/emacs-websocket, created a emacs community.

Emacs Community: https://plus.google.com/communities/114815898697665598016

There, anyone can post and share tips, ask questions. Hope to see you there.

Emacs: Copy Rectangle Region to kill-ring 🚀

I wanted to thank Matthew L Fidler [https://github.com/mattfidler ] again. He's been hacking on ErgoEmacs keybinding package. Basically a rewrite. Massive work. Still going. I can see a lot emacs lisp expertise going on there.

Also, before that, David Capello [https://davidcapello.com/] did the heavy lifting. Made the package from simple global set key into a full-featured minor mode, and started supporting various layout and international layouts.

on its own page now: Emacs: Name Completion

Wrote a simple elisp command to insert a random CSS color string. See: Emacs: List Colors, Name, Hexadecimal

Great news. MELPA now hosts the latest dev version of ErgoEmacs keybinding package. http://melpa.milkbox.net/#ergoemacs-mode

Emacs Lisp: Move Code to Files

emacs lisp problem: there's a reverse function. But it doesn't work on vectors.

Worth reading again: Guy Steele on Parallel Programing: Get rid of cons!. When coding in emacs lisp, try not to use list as much as possible. Use vector instead. See also: Emacs Lisp: Sequence, Array

Ask Emacs Tuesday.

Ask Emacs Tuesday. Today i like to ask you all this question. If you are a perl/python/ruby developer, what emacs packages, configuration, do you use? Please do post your .emacs on github (or other) too. After today, i'll do a summary to share with you all.

I'll start with myself. Perl i had many years of day job experience. I use cperl-mode (part of emacs now). I have a comparison of perl and cperl here: Emacs: perl-mode vs cperl-mode Python i do as a hobby for many years, and recently been learning ruby. Overall, i honestly can't say i use many packages/setup that are specific to these languages. The bulk of convenience lies in generic emacs features. They are, all the completion packages i mentioned recently [see Emacs: Name Completion]. Then, heavy use of emacs features and setup, such as dired, bookmark, many find replace features, dired-do-query-replace-regexp, keyboard macro, “shell”, “shell-command”, many other …. Hard to really pick out specific ones. (almost all of these generic features you can learn more at Xah Emacs Tutorial )

For python, i also really just use the basic python-mode that come with it, nothing else extra. Worth mentioning is whitespace-mode. [see Emacs: Show Whitespaces] There's also https://github.com/antonj/Highlight-Indentation-for-Emacs/

some people i know have one specific setup/environment for one of perl/python/ruby. So what are they? Also, if you know a expert who code one of these languages with emacs, please do post their git .emacs URL (or other repository). For those emacs-prelude and other pre-packaged emacs users, do tell us what setup there you find really helpful.

especially interesting are those setup with ipython or other some type of dynamic integration. Also, some provide doc integration. Which are they? (i used to have perl doc in info format, but not now. Where can i find perl/ruby/python doc in info format?) I've also heard keys that lets you directly read the doc string of function/method of perl/python/ruby, similar to emac lisp's describe-function. Anyone have such setup? So, please do go thru your day work tell us what packages/features you can't live without for doing dev with that lang.

I'll do a summary afterwards, and hopefully it'll be heplful to many. thanks.

New Dev Version of ErgoEmacs Keybinding Package

Matthew L Fidler did a huge overhaul of the ErgoEmacs keybinding package. LOTS new features. If you are adventurous, you might want to take a look and try the latest. Thank you Matt!

Here's a quick summary of the changes/new features:

You can read detail in the included _HISTORY.txt file.

The dev version is here: http://code.google.com/p/ergoemacs/source/list (git doesn't let you checkout a sub dir, so you'll have to checkout the whole ErgoEmacs.)

Check it out. Comments or bugs can be posted at the dev forum https://groups.google.com/group/ergoemacs?hl=en

Stable version (v5.3.7) that's 2 year old is in a zip file here: ErgoEmacs Keybinding, in case you want to compare the differences.

Note: the version on MELPA is also kinda old. It's slightly newer than 5.3.7, but is also outdated. (last i checked, it's still based on svn source, which we changed to git a while ago. I haven't had time to contribute to MELPA. Thanks to the person who puts it on MELPA.)

I'm currently looking for work, so won't be able to contribue much this month.

Yesterday, i spent a hour doing a regex in elisp. Failed. Frustrated. Switched to python, done the job in 20 seconds.

I have text like this:

<header>
<span class="xsignet">∑</span> <a href="../index.html">ErgoEmacs</a><a href="emacs.html">Emacs</a><a href="elisp.html">Lisp</a> ◆
lots html, with newline
</header>

I want to replace the whole by a static string, on a few thousand files. I tried many patterns in emacs:

<head>.+</head>

<head>[[:print:]]+</head>

<head>[
[:print:]]+</head>

<head>[[:ascii:][:nonascii:]]+</head>

I spent a hour. Fail. The last regex gave this error: “Stack overflow in regexp matcher”.

In python, this does it:

# python
re.compile(ur"""<header>.+</header>""", re.U|re.M|re.DOTALL)

In elisp, you have these char classes: {[:graph:], [:nonascii:], [:print:]}. Char Classes (ELISP Manual) The documentation is not detailed. I don't think anyone uses it. And, it doesn't seem to work. (not to mention the toothpick syndrome when the regex is in lisp code.)

For example, elisp manual says:

`[:print:]'
     This matches printing characters--everything except ASCII control
     characters and the delete character.

Moral: emacs regex sucks donkey ass.

Addendum: LOL. Actually, i just discovered that i was using <head>… in elisp, but it should be <header>…. So, NEVERMIND!

Emacs: Name Completion