Xah Emacs Blog Archive 2017-07
Elisp for text processing in buffers
reddit discussions https://www.reddit.com/r/emacs/comments/6qpbka/elisp_for_text_processing_in_buffers/
my take:
for me, the basic problems are, from more critical to less:
- emacs cannot open large files. e.g. 10 megabytes file becomes very slow.
- emacs has to load whole file into memory. It cannot just read a line of a file. Basically, you can't use emacs to process say http server log files.
- emacs has problem with long lines. e.g. many modern lib generate html/js output all in 1 single line.
- elisp is at least 6 times slower than python ruby perl.
- emacs regex sucks. (1) backslash problem. (2) Unpredicable syntax table dependent e.g. for word. (3) Verbose syntax e.g. in
[[:digit:]]
instead of\d
. (4) Less powerful. - string lib sucks. Though, usually you'd use buffer functions, still, a robust string lib helps a lot.
- when using elisp as text processing script, many obscure details one has to pay attention to. e.g. you don't want to use find-file to open cuz that loads the major mode with syntax coloring, undo on, or lots packages have added hooks when a file is opened, need to possibly turn off auto backup, etc.
- the no raw string quote is painful. e.g. in perl/ruby you use single quote or q[], in python you use tripple. In elisp, you have to sprinkle backslashes into the string. Not practical when the string is long, such as comp lang code or regex code. (or you put the string into a file then read it in, but that's another inconvenience)
The emacs buffer type is far more powerful than string type. The addition of “point” datatype and others, narrow to region, move/search forward backward, insert/replace text anywhere, makes it far more powerful than any regex. I thought i'd write all text processing in elisp. But these days, i avoid it, unless i want to use it interactively while in emacs.
Do you use digit arguments a lot?
Never. Because:
- the digits args sit on a whopping ~21 easy keys spots, with Control and Meta, 0 to 9 plus negative sign. Even if you use
digit-argument
frequently, it's not good use of key spots, because lots other commands are more frequently used. - am against commands that require one to think about “how many” (vi's style do this a lot.). I think it's a brain cycle drain. Often you overshoot or undershoot. Better is to hold a key and repeat, which relies on visual only.
- when a digit argument is required, i use the universal
universal-argument
with C-u. - Relative very few command take a digit argument. And even when they do take a universal-argument, the behavior is idiosyncratic to each command. This makes them much less useful.
reddit discussion https://www.reddit.com/r/emacs/comments/6qhhad/do_you_use_digit_arguments_a_lot/
emacs lisp: how to write indentation for major mode
Thanks to Johanne, alpha, alexander, for my first 3 patrons.
my next plan, see https://www.patreon.com/posts/13497775
god mode, the worst keybinding package in emacs
Dear chris done, thanks for chatting a couple years ago, but am sorry, your god mode is the most worthless keybinding package in emacs, yet with the most shameless hacker pride name.
to anyone using god mode. Turn on sticky key in your OS, and you'll be more efficient in no time, sans any hassle of memorizing key transformation contortion.
to anyone more interested in efficiency: for any complex keybinding you find yourself using, just define a key sequence starting with a lead key such as f8. You can do this, without installing any package, and within 1 minute, just 1 line of config.
(global-set-key (kbd "<f8> <f8>") 'save-buffer)
Then, next day, when another control meta gets you, just define another sequence. Soon, you'll have all key sequences, part of your muscle memory, yet, all default control meta combo still works.
but i don't like reaching for function keys!
Yes, each to his own. But also note that f8 can be any key. For example, set capslock to f24, and let f24 be the lead key. So, C-x C-s could be just capslock capslock, or capslock k, etc. The capslock could also be alt, so it's under thumb.
if you are using Microsoft's ergo keyboard, it has a big menu key on right side. Can just use that as leader key.
reddit discussion https://www.reddit.com/r/emacs/comments/6q2pow/my_current_solution_to_emacs_pinky_hope_it_helps/dku8t1y/
Be My First Patreon
dear Xah readers,
now i have a patreon account.
if you find my writing helpful, throw in some money.
https://www.patreon.com/xahlee
I haven't wrote anything on patreon yet. May have to get on with the program, and start some marketing stuff, like, say nice things, put up a photo, etc.
but you probably knew me already. Be my first patreon.
I'll probably channel my emacs writing into more user-based tutorials. That is, i write what you want to read, instead of what i think is good.
$5 to $10 monthly, would be great.
Vote with your money. Thanks.
Emacs: Xah Fly Keys now supports workman layout. thanks to “alphago”.
thanks a lot to Arseniy for using Xah Fly Keys and support! ♥
Emacs: Xah Fly Keys
[http://xahlee.info/emacs/misc/ergoemacs_vi_mode.html#comment-3435173190]
Emacs: Paste or Paste Previous 🚀 (the command now can paste n times)
emacs 26 new line number mode
Currently building emacs. I want the shiny new line numbers.
Common Lisp sucks
See also:
Famous Programers on How Common Lisp Sucks
Emacs: Organize Init File (major update)
Emacs: Reformat Lines for Source Code 🚀 (fixed a bug where region remain active)
ELisp: thing-at-point (minor update)
ELisp: Get Buffer String (more edit, expanded a bit.)
Sigil is Back
Now am using $sigil again.
It was like this ξx
for a number of years, then finally gave up due to complaints, i used -x
in past year, but now am using sigil again, this time it's $x
.
Sigil has great syntactic advantages. I don't want to do without. The problem with a dash is that it's too similar to all other builtin lisp symbols, defeating the purpose of sigil in the first place.
I've updated all my elisp packages to use the new sigil.
[see Xah Emacs Packages]
And also changed all code on the website.
For the reasons why sigil, see
ELisp: Mark, Region, Active Region (major update)
ELisp: Get Buffer String (on its own page)
ido mode and icomplete mode
The following are all changed in major ways.
- Emacs 27: ido mode 👎 (new page)
- Emacs: icomplete, Name Completion (new page)
- Emacs: Switch Buffer (complete rewrite)
- Emacs: icomplete vs ido mode 👎
- Emacs 22: iswitchb vs ido mode 👎
- Emacs: Init File Tutorial
ELisp: Get User Input (correction on tutorial code )
Emacs: Name Completion (rewritten)
Emacs: icomplete vs ido mode 👎 (major update)
Emacs: Copy Current Line If No Selection 🚀 (more bug fix, on xah-copy-line-or-region
)
Emacs Mode Line Problem (minor update)
this article, 2008, was one of those that people called me a troll for. And today, you can enjoy the 6 or so mode line enhancement packages.
mode line modification, is one of those things, like color themes, that people love to use.
Emacs: Xah Math Input Mode (xah-math-input.el) (added screenshot)
ELisp: Get User Input (updated. added a example from picking from a list)
Emacs: Delete Text Block 🚀 (more code update. now delete selection if there's one)
Emacs: Reformat Lines for Source Code 🚀 (code major rewrite)
Emacs: Interactive Find Replace Text in Directory (updated. showing how to use the xref buffer)
vim fun: construct byte sequence and show in vim
echo -n "e0 81 b3 e0 81 a8 e0 81 af e0 81 b4 e0 81 b3 e0 80 a0 e0 81 a6 e0 81 a9 e0 81 b2 e0 81 a5 e0 81 a4" | xxd -r -p | vim -
Emacs: Delete Brackets by Pair 🚀 (code update. almost a rewrite)
Emacs Init: Highlight Brackets (updated)
Emacs: Copy Current Line If No Selection 🚀 (fixed a bug of duplicated copy when cursor is at end of buffer)
Emacs: Org Mode Customization (some useful settings)
Emacs: Init File Tutorial (major update. Added lots config and explanation.)