Xah Emacs Blog Archive 2011-07 to 2011-09

Updated: Emacs: Unicode Tutorial. Added info about how to insert a Unicode character by its decimal code point.

Updated a page that i wrote in 2006. The code was embarrassing. Here's the updated page: Elisp: Writing a Wrap-URL Function. Elisp level: beginner.

Here's a answer to last week's elisp quiz. Elisp: Command to Replace HTML Entities with Unicode Characters.

Emacs Regex Quirk: Matching Beginning/End of Line/String/Buffer

Elisp: Fix Dead Links

Emacs Quiz of the Day: replace-html-entities

Write a function “replace-html-entities”. If there is a text selection, work on the selection. Else, work on the current paragraph (defined by 2 line breaks)

Replace all named HTML entities such as © to ©. (see entity list here: HTML XML Entities .)

i'll post a answer on Monday.

If you are new to elisp, the following articles will be helpful. One of the article basically spills out the solution.

Note: for those who know elisp well, your command should also replace all entities in decimal form (For example, ©) or hexadecimal form ©. There's a tricky part in this problem. Your code should not introduce extraneous transformation. For example, suppose the input file discusses HTML language, and it has this text in it: &copy&#59;. It should not become ©.

Solution to yesterday's problem: Elisp: Replacing HTML Entities with Unicode Characters.

Emacs Quiz: Replacing HTML Entities with Unicode Char. See: http://xahlee.blogspot.com/2011/09/emacs-quiz-replacing-html-entities-with.html

Emacs Lisp Function to Trim String

Emacs lisp does not have a function that removes space from the beginning and end of a string. You must use replace-regexp-in-string for that. Here's a function that does it.

(defun trim-string (string)
  "Remove white spaces in beginning and ending of STRING.
White space here is any of: space, tab, emacs newline (line feed, ASCII 10)."
(replace-regexp-in-string "\\`[ \t\n]*" "" (replace-regexp-in-string "[ \t\n]*\\'" "" string))

See also:

few days ago i posted a article on string-rectangle, but it wasn't a finished article and was posted by mistake. Here's a more complete article: Emacs: Edit Column Text, Rectangle Commands

Programing Language: LISP Syntax Problem of Piping Functions

Updated: Elisp: print, princ, prin1, format, message

Elisp: Writing a Date Time String Parsing Function

Of those who bought my emacs tutorial recently, there's a new free update. (fixing a external link error) Just email to xah@xahlee.org with subject “xah emacs tutorial update”, then i'll email you the download location.

If you haven't bought it, you can buy at Buy Xah Emacs Tutorial.

Elisp: HTML Processing: Split Annotation

Elisp: Writing a make-citation Command

Emacs: Preserve Your Split-Panes Configuration with winner-mode

Thanks to Damon Haley, Lindner Technologies, Shuyang Zhao for donation. Very much appreciated.

Emacs Lisp vs Perl: Redux. Which Do You Prefer?

I wrote this article: Text Processing: Emacs Lisp vs Perl. Today, some discussion happened on Google's g+ social networking site, and Randal L Schwartz made the comment that he actually prefer Perl over Emacs Lisp for text processing. See the discussion at Source plus.google.com

Note: Randal is a well known expert in Perl, co-author of Perl (1st edition) and Learning Perl, and also has written at least one elisp package in GNU Emacs (a pretty printer for elisp at lisp/emacs-lisp/pp.el)

So, if you are fluent in using both Perl and Emacs Lisp for TEXT PROCESSING, which one do you prefer? and why? (For this purpose, Perl here can mean any of Python, Ruby, Scheme.)

Comment or vote (upper right) at: http://xahlee.blogspot.com/2011/08/emacs-lisp-vs-perl-redux.html. Result will be posted here in a week.

Here's result:

If you are fluent in using both Perl and Emacs Lisp for TEXT PROCESSING, which one do you prefer? (Perl here can be any of Python, Ruby, Scheme.)

Updated and Moved into a article by itself: Emacs: Set File to Open in a Major Mode.

Emacs YASnippet Tip: Expand Whole hyphenated-word as Input

Updated: Emacs: List/Delete/Highlight Matching Lines, Sort/Reverse Lines

Elisp: Chinese character Reference Linkify

Emacs Tip: Jump to Previous Marked Position

Often, you need to go to a previous position in a buffer. For example, you are editing a big source code that's few hundred lines. You want to look at some function's definition, but then you want to return to the current position.

Emacs has a buffer mark ring and global mark ring that records mark positions and lets you jump to it.

Jon Snader's Emacs Lisp tutorial for Validating Matching Pairs

Jon Snader (jcs) wrote 2 versions in elisp for our previous programing challenge on Validate Matching Brackets.

Ι'll be going over his code soon. His blog is well annotated, so is a good one if you are learning emacs lisp, from a different style than mine. His article is at: Xah's Challenge (Part 2) By Jon Snader (jcs). At http://irreal.org/blog/?p=165.

Elisp: Get Command Line Arguments

Answer to the challenge 2 days ago: Elisp: Batch Script to Validate Matching Brackets.

emacs tip: inserting source code in org-mode

When using org-mode, you can insert a snippet of programing language code.

Type <s then Tab. It will insert this markup:

#+begin_src ▮


The above is the syntax for literal text. (similar to the concept of Perl and PHP'S Heredoc.)

Then, type “emacs-lisp” so you have:

#+begin_src emacs-lisp


this tells org-mode this snippet is emacs-lisp code. The “emacs-lisp” there can be any mode. For example: “html”, “perl”,“haskell”, etc. (technically: the value of the variable major-mode, then minus the “-mode” string at the end.)

orgmode.org 15.2 Easy Templates

For basics of org-mode, see: Emacs: Writing Outline, org-mode Tutorial.

Elisp: Transform HTML Tags from “span” to “b”

Little Parser Problem Challenge: Matching Pairs Validation

See http://xahlee.blogspot.com/2011/07/little-parser-problem-challenge.html

Thanks to Xiang Xin Luo for donation.

For those of you who bought my Emacs Tutorial, just send me a email and i'll mail you a update. (xah@xahlee.org) In the subject, put “xah emacs tutorial update”.

Buy at Buy Xah Emacs Tutorial. Thank you for support!

Emacs: Unique Buffer Names

If you work with files of the same name often, their buffers names are hard to distinguish. For example: {“index.html”, “index.html <2>”, “index.html <3>”}. You can make the buffer name display part of the dir name. Place the following in your emacs init file:

;; make buffer names easily identifiable
(require 'uniquify) ; bundled with GNU Emacs 23.2.1
(setq uniquify-buffer-name-style 'forward)

Emacs: Byte Compile Elisp Files (inspired from Source tsengf.blogspot.com)

Update: Emacs: Dired Customization

Emacs: perl-mode vs cperl-mode

Emacs: Use Alias for Fast M-x.

Elisp: Batch Transform HTML to HTML5 “figure” Tag