Xah Emacs Blog

Master emacs+lisp, benefit for life. Testimonials. Thank you for support.

Tips & Tricks for emacs and emacs lisp.

Steve Jobs on keyboard. something is coming. https://onkeyboards.com/

Jesse Vincent's keyboard design is near completion.

Jesse Vincent, co-founder and CTO of Keyboardio, .

the video is a bit of marketing, but nevertheless, it's a excellent keyboard. Visit Vincent's site at http://www.keyboard.io/

Why Microsoft Outlook has 【Ctrl+f】 for forward email, while every other Microsoft software has it for Find? Reminds me of emacs & rms. http://blogs.msdn.com/b/oldnewthing/archive/2014/07/15/10542285.aspx

via Sujith Abraham

fixed a bug. Yesterday's change broke getting http links. Emacs Lisp: Command to Extract URL

by the way, the command is in Emacs: Xah HTML Mode. So, github to be continuously updated.

Emacs Lisp: Ban Syntax Table

Are you using Emacs Gnus to read webfeed? emacs gnus doesn't support atom format last i heard. Try elfeed. https://plus.google.com/+XahLee/posts/5JrhNjhtXRT

Emacs Lisp: Command to Extract URL (updated code. Now works on both single/double quoted string.)

Emacs's Mode Line Suggestions (repost)

Microsoft Keyboard: How to Disable the F Lock Key (repost)

Emacs Keybinding: the Power of Key Sequences (minor update)

there's a ergoemacs keybinding for the editor Light Table. See: https://github.com/nikitakit/LightTable-ErgoEmacs

JavaScript is the future. I worked out a tutorial in the past year. Much more in depth than my 10 years dabbling in emacs lisp. Why would you read my tutorial when there are lots on the web? Because i believe there's nothing better out there, except the printed books. In particular, it is written in my unique Xah Style. Namely, simple, example based, and as close to formal language as possible. (the “formal language” part may scare you off, but try it.) Xah JavaScript Tutorial

Tweet it, link to it, buy. Thank you.

emacs lisp: twitterfy-shorten text

(require 'xfrp_find_replace_pairs)
(require 'xeu_elisp_util)

(defun xah-twitterfy ()
  "shorten words for twitter."
  (interactive)
  (let* ((bds (get-selection-or-unit 'block))
         (p1 (elt bds 1))
         (p2 (elt bds 2)))
    (replace-pairs-region p1 p2 '(
                                  [" are " " r "]
                                  [" you " " u "]
                                  [" and " " & "]
                                  [", " ","]
                                  ["..." "…"]
                                  [". " "。"]
                                  ["。 " "。"]
                                  ))))

it seems that many emacs users don't know these commands. Now and then i hear people surprised by their existence after n years of using emacs. Emacs: List/Delete/Highlight Matching Lines, Sort/Reverse Lines

Emacs Lisp: Filter a List

updated the command to delete current file. Now, will also do backup for buffers that's not a file. Emacs Lisp: Delete Current File

Vim: How to Remap the Escape Key? (on its own page)

fixed “xah-backward-block” Emacs: Move Cursor by Paragraph or Text Block

ergoemacs-mode is now in GNU ELPA http://elpa.gnu.org/packages/ergoemacs-mode.html

yay. We had all to sign papers. The code is primarily by Matthew Fidler. David Capello and me worked on it before.

i want to especially thank my friend Xue Fuqiao (aka xfq) for the suggestion and helping the process.

DAS Keyboard 4 Professional keyboard

DAS came out with a new keyboard. DAS Keyboard 4 Professional keyboard

pity, it's the same old PC form keyboard, ones that whack your hand.

hacker news discussion https://news.ycombinator.com/item?id=7979073

see also Computer Keyboards, Layouts, Hotkeys, Macros, RSI ⌨

emacs lisp: what does “prog1” do?

learned about prog1 today.

(info "(elisp) Sequencing")

thanks to Dan Lentz

Programing Language: Function Dependency

Can Emacs Lisp Fix Its Namespace Problem by Copying JavaScript Practice?

emacs: ergoemacs-mode link change

ergoemacs-mode news, from Matthew L Fidler. Link is changed

https://ergoemacs.github.io/ergoemacs-mode/   ← old
https://ergoemacs.github.io/           ← new

the change is made because: before, when you check out, you get some 100 mega bytes of stuff, which includes the ergoemacs-mode website and all the images about layout.

now, the code and home page are separate github projects.

be sure to update your links.

there's automatic redirect. But some link with specific URL may break, Matt is fixing them. Thanks Matt.

comment at https://plus.google.com/113859563190964307534/posts/WkoAadUJgwh

emacs: xah fly keys package

for those of you heavy keyboard tinkers, i've pulled dependent commands into xah-fly-keys.

download at https://github.com/xahlee/xah-fly-keys

if you have issue, just file bug report there.

i'll incorporate this into ergoemacs-mode as a theme one day.

note:

there are 2 parts to my keybinding. One is fast-repeat commands, and these are mostly cursor movement commands and text deletion commands. These are in xah-fly-keys, which is also what ergoemacs-mode is about. Typically, these are top 20 commands you use most frequently, and everybody use all of them every minute. 〔☛ Emacs: Fast-repeat vs Non-fast-repeat Commands & Keys

the other part is the hundreds other emacs commands. I've designed a key set for them, as key sequences, 95% complete. Right now they are in my emacs init file. I'll write about it down the road, and push it into xah fly keys.

xah fly keys home page ergoemacs-xah Mode. (naming is yet to be resolved. Not sure it should be ergoemacs-xah or ergoemacs-vi or xah-fly-keys.)

Programing Language: Fundamental Problems of Lisp (minor update)

ergoemacs's 7 years old

;; version 1.0, 2007-08-01. first version.

so, next month, ergoemacs's gonna be 7 years old. The original site: ErgoEmacs Keybinding: a Ergonomics Based Keyboard Shortcut System

the tab & space emacs lisp mode

in xah-elisp-mode, all you ever have to do is press tab or space. Never need to insert a paren or indent or whatnot. neva❕

just type, then press tab or space.

https://github.com/xahlee/xah-elisp-mode

xah fly keys mode. Now on github as a project. See ergoemacs-xah Mode.

emacs lisp: region-active-p vs use-region-p

changed region-active-p to use-region-p sitewide.

what's the difference? if you look at the source code, region-active-p just check if transient-mark-mode is on and mark-active is true. And use-region-p added a check for use-empty-active-region.

(defun region-active-p ()
  "Return t if Transient Mark mode is enabled and the mark is active.

Some commands act specially on the region when Transient Mark
mode is enabled.  Usually, such commands should use
`use-region-p' instead of this function, because `use-region-p'
also checks the value of `use-empty-active-region'."
  (and transient-mark-mode mark-active))

updated Emacs: What's Region, Active Region, transient-mark-mode?

on the web, almost every day you see a post about Repetitive Strain Injury. hand pain! here's a recent one for example http://geekhack.org/index.php?topic=59828.0

who wrote emacs since 2000?

since few years ago, i have a habit to see who's the author of a package.

we all know that GNU Emacs was first emacs written in lisp, and is written by rms. But other than rms, most have a hard time coming up with a second name.

emacs's been around for 3 decades now. There are many fundamental and non-trivial core features in past few years. For example, who implemented the Unicode engine in emacs? who implemented the behavior where arrow down key moves by visual line? Who revamped emacs's completion engine? who implemented right-to-left languages support? who build the Chinese input system?

for packages, it's very easy to see who wrote it. Just call describe-function, then tab a few times to the elisp source code. (if you have emacs compiled, it's better, because binary emacs don't come with source code)

i started to look at author info since emacs 23, and link and thank them: New Features in Emacs 23

comment at https://plus.google.com/113859563190964307534/posts/VvxuYV4mY16

Bad Advices from Programers about Typing & Keyboard (RSI) Bad Advices from Programers about Typing & Keyboard (RSI) (repost)

Emacs Lisp: How to Determine If Cursor is Inside String or Comment

Emacs Lisp: Determine OS, Emacs Version, Machine Host Name (minor update)

Emacs Lisp: Insert Date/Time (repost)

Emacs Lisp: How to Modify Syntax Table Temporarily

just finished reading John Wiegley's 〈Git from the Bottom Up〉.

Git from the Bottom Up By John Wiegley. @ http://jwiegley.github.io/git-from-the-bottom-up/

this is excellent for people who have already used git on a daily basis, and wish to understand how it works underneath.

John Wiegley is a emacs expert, and also a heavy org-mode user. He has been interviewed by Sacha at http://sachachua.com/blog/2012/06/emacs-chatting-with-john-wiegley-about-the-cool-things-he-does-with-emacs/

if you want practical git, check out my beginners tutorial Git Tutorial: Practical Git in 1 Hour

improved “xah-select-text-in-bracket” using “with-syntax-table”. see Emacs: extend-selection, select-text-in-quote, select-current-line, select-current-block

Emacs: Remapping Keys Using key-translation-map (updated)

Emacs Hello ergoemacs-mode Again

Emacs: Enable Undo in Buffer (on its own page)

Thanks to jcs at irreal.org

xah-elisp-mode is ready for public use. Emacs: Xah Emacs Lisp Mode

Been working on it in past week full time. Tremendous Thank You for many who have donated.

Try it first without using auto-complete-mode or yasnippet.

Emacs: How to Define Super & Hyper Keys (minor update)

Emacs: extend-selection, select-text-in-quote, select-current-line, select-current-block (updated)

Emacs: Commands to Move Cursor by Brackets, Quotes (updated)

Emacs Lisp: Move Cursor to Beginning of Line or Block (updated)

Emacs: Move Cursor by Paragraph or Text Block (updated)

Emacs Lisp Toothpick Syndrome

Emacs: Problems of the Scratch Buffer (minor update)

Emacs: New Empty Buffer

Syntax Coloring in Editors

emacs: display function parameter

learned (turn-on-eldoc-mode). It displays the function's parameter in the minibuffer, of the function your cursor is on. Works in emacs-lisp-mode and other programing language modes.

i learned this from sacha's http://emacslife.com/how-to-read-emacs-lisp.html

eldoc-mode is written by Noah Friedman, first created in 1995.

Emacs: Turn Off Auto Backup; Set Backups into a Directory; How to Delete Backup Files (updated)

emacs: efficient ways of going into a directory

dired-jump, when in dired, it'll go up a directory. Very cool. Because, normally you have to press ^. But, if you've given a easier key to dired-jump than that, then you just press the dired jump key instead!

you'll need this in your init file first:

(require 'dired-x)

it's bundled with emacs for years.

note: you should never need to call dired directly. Either use dired-jump, or use find-file. (be sure to have ido on, and when in ido-find-file, press 【Ctrl+d】 to go into dir.)

i haven't called dired command for about 6 years. First, i noticed that find-file will do equivalent when your path is a dir. This way, you don't need another key squatting a key spot. Just give a simple key for find-file. (in ergoemacs-mode, the find-file has key 【Ctrl+o】) Then, ido improves the find-file situation by having automated path completion, so that saves you much key strokes. Then, dired-jump replaced other methods to go into dired more than 50% of the time.

comment at https://plus.google.com/113859563190964307534/posts/RAjAqcteEGu

isearch-forward-word search for sequence of words, regardless it's separeted by space or - or _

Emacs: Search & Highlight Words (updated)

htmlize syntax color

today's fruit

(defun xah-redo-syntax-coloring-html-buffer ()
  "redo all pre lang code syntax coloring in current html page."
  (interactive)
  (let (langCode p1 p2)
    (goto-char (point-min))
    (while
      (re-search-forward "<pre class=\"\\([-A-Za-z0-9]+\\)\">" nil "NOERROR")
      (setq langCode (match-string 1))
      (setq p1 (point))
      (backward-char 1)
      (xhm-skip-tag-forward)
      (search-backward "</pre>")
      (setq p2 (point))
      (save-restriction
        (narrow-to-region p1 p2)
        (xhm-dehtmlize-precode (point-min) (point-max))
        (xhm-htmlize-region (point-min) (point-max) (xhm-langcode-to-major-mode-name langCode xhm-lang-name-map) t)))))

so, i press one button, and the current HTML file's pre tag of programing lang source code are all regenerated.

to redo my entire website's syntax coloring, i can run this:

(defun my-process-file (fPath)
  "Process the file at path FPATH …"
  (with-temp-buffer
    (insert-file-contents fPath)
    (xhm-redo-syntax-coloring-buffer)
    (write-region 1 (point-max) fPath)))

(require 'find-lisp)

(mapc 'my-process-file (find-lisp-find-files "~/web/" "\\.html$"))

why do i want to regenerate? because i'm using several of my own emacs modes for coloring, including xah-elisp-mode, xah-html-mode, xah-css-mode, xah-js-mode, because the default doesn't color many keywords. But in my modes, i constantly add new keywords or tweak how i want them colored. For example, in JavaScript, should coloring be grouped by keywords, object name, function name, or native object vs hosted object, or methods vs properties, etc. So, when i made a change to how the mode colors, i sometimes want to update all pages on my site.

for the basics of how this works, see Emacs Lisp: Syntax Color Source Code in HTML

comment at https://plus.google.com/113859563190964307534/posts/7tcHTo5Ys26

emacs lisp: name your predicate ending in question mark?

by convention, predicate functions in emacs lisp ends in “p”. ⁖ file-exists-p

but it's inconsistent. Some functions ends in “p” but is not a predicate. ⁖ {pop, defgroup, make-sparse-keymap, forward-sexp}.

also, some ends in “-p” some without the dash. ⁖ {file-exists-p, integerp}

you should name it ending in “?”. See: Computer Language: Predicate Function, Terminology, and Naming Convention

new version of emacs tutorial. Heavily updated in past weeks.

Buy Xah Emacs Tutorial

thanks to so many of you for support. The new version will be emailed to you today.

tweet, repost, share, buy. Thank you.

Keyboard: What's the Difference Between Alt Graph Key, Compose Key, Dead Key?

see also: A Curious Look at GNU Emacs's 1000+ Default Keybinding (updated)

Emacs: Newline Representation ^M ^J ^L? (updated)

Emacs: Search & Highlight Words (complete rewrite)

Emacs Lisp: Which Part of Symbol Don't You Get?

How to Write grep in Emacs Lisp (updated)

Emacs: Save/Restore Opened Files, Windows Configuration: desktop-mode (updated)

Emacs: List Buffers (updated)

Emacs: Open Recently Opened File: recentf-mode (updated)

Emacs: iswitchb vs ido mode (updated)

Emacs: icomplete vs ido mode

Emacs: Switch Buffers, Ido Tutorial (updated)

what happens to a package when it joins the mothership?

once a package goes into GNU emacs, as a property of FSF, the package becomes moribund.

all innovation happens outside of it, and lots of re-inventing the wheel, but usually better wheel.

well, it's not exactly dead, but will be revived and improved after half a decade, when there are several better wheels out there.

comment at https://plus.google.com/+XahLee/posts/4kzBadna2Gq

Like what you read? or share some

Past Articles by Date