Xah Emacs Blog Archive 2011-07

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

Updated a page that i wrote in 2006. The code was embarrassing. Here's the updated page: Elisp: URL to HTML Link. 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, Output

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

Emacs: HTML, Make Citation Link

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 Google Plus 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 [https://plus.google.com/112757647855302148298/posts/8VUt9erSuRp]

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 Default Major Mode.

Emacs YASnippet Tip: Expand Whole hyphenated-word as Input

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

Elisp: Chinese character Reference Linkify

Emacs: Jump to Previous Position

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: Org Mode, Work with Source Code

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

Little Parser Problem Challenge: Matching Pairs Validation


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

If you have a question, put $5 at patreon and message me on xah discord.
Or support me by Buy Xah Emacs Tutorial