Xah Emacs Blog Archive 2018-08
is emacs lisp best for text processing?
for 11 years, starting in 2006, i tried to port/write all my text processing needs in emacs lisp. I thought emacs buffer datatype power is unbeatable. Gradually, i realized it's a mistake, since 2016. here's a account in 2012. One Language to Rule Them All? Or, What Language to Use for Find Replace? read that first. Continued.
today, i find that doing text processing in emacs lisp is a mistake. problems: ① no literal quote. If your find string is a snippet of regex, spend 10 min to manually quote it first. ② elisp regex sucks donkey ass. ③ the lang is at least 6 times slower than python perl.
None of these problems are intrinsic to emacs lisp. They could be fixed, relatively easily. But the GNU emacs dev have lots org problems, and the emacs cult prevents much progress, suppress any voice of its problems. All we do daily is sing the song of emacs superiority.
it's unfortunate, because elisp with its buffer datatype is super powerful (which lets you move a “cursor” back and forth, do regex on parts, etc), and emacs the whole is text processing system. Plus, any code can also run interactively by design.
about 3 years ago, i stopped writing new text processing tasks in elisp, unless it's just for current buffer. This is pretty sad. Now, it's back to calling external software (e.g. grep). you want the speed of other lang, but you want the syntax coloring and interactivity in emacs.
now, my new lang for text processing is golang. For processing thousands of files each being typical html file size, if you have a spinning disk, it's not faster than perl python. The disk IO is the bottle neck. (flash drive helps, or huge memory)
so now am thinking if i should write elisp wrapper to golang scripts, e.g. emacs M-x grep call unix grep, but + color and clickable link. This is sad, cuz the wrapper doubles the coding work, and communication makes the whole thing slow again. if your find string is regex snippet, good luck passing it unharmed.
i kept thinking, it's not hard for someone like Daniel Colascione to single handedly rewrite emacs from scratch within 1 year. The problem is, there'd be no money support, plus, the community hate. Until it take off, most would probably give it cold shoulders.
if compatibility is ignored, the task would be much easier, someone could do it in golang or such, a editor with ALL emacs qualities we love. But again, money is a problem. Nobody would pay. Nobody wants to change habit. Only a corp like github can risk (e.g. atom).
[xah-fly-keys rough edges By Jaredj. At https://j.agrue.info/xah-fly-keys-rough-edges.html ]
jaredj wrote about some problems with xah-fly-keys.
just fixed the e and r issue! at github.
thanks jaredj. I don't see comment or contact on your blog. So here's some comment.
About c for copy not including end of line, that someone has raised an issue on github. (closed now) Please look there for discussion.
about o not opening like vi. i think someone also asked about that. I think mostly it's from vim habit. But still, the question is open one. The issue is this:
vi's o will: ① add a line below current. ② move cursor there. ③ activate insert mode.
about activating insert mode, that's another issue. namely, whether
there should be more than 1 or even more than 2 ways to activate insert
mode. But let's ignore that for now. So the issue now is, should it add
a line below and move cursor there, and not caring about current cursor
position. As opposed to, add a newline character after cursor (the
the open line is similar to pressing return. The difference is one insert newline after cursor, and the other inserts before. (another similar issue is when inserting space. Space key insert space before cursor. While
and the question is, should you actually need 2 commands to insert newline that only differ by before/after?
i find the emacs open line useful. Because the enter key is often bound to also do special things, like expand abbrev, indent, sent stuff, etc.
the general question is, what minimal command set is more essential, or more frequently needed. I can't say emacs way is. Some more discussion about this at emacs and vi: Science of Command Efficiency
emacs blogs to read
on mastodon trayofbees is building a emacs bot https://mstdn.io/web/statuses/100643011419554187 go there suggest maybe.
my list is probably
- steve yegge https://email@example.com/
- Chris Wellons http://nullprogram.com/blog/2014/01/04/
- john kitchin http://kitchingroup.cheme.cmu.edu/blog/
- howard brams http://www.howardism.org/
i don't read much blog actually. 10 years ago some. then blogs collapsed, google killed its Reader. even less people blogs. the thing is, as info gets rampant and specialized, generic blogging lost value. unless u specialize in 1 very specific topic, as a job, n write that ONLY.
i think blog traffic disappeared all across. 10 yrs ago i have maybe few hundred reading my emacs blog. i dunno today, maybe less than 100 who does few times a week.
today is such that, if u have 20 min a day to read random. there's wikipedia, n dedicated tutorials on diverse topics. (plus thousand spam from corps trying to sell u xyz). blogs can hardly compete. blog is somewhat more connection with people and twitter etc is stomping on it.
massive update. Soon, you can hook it up to use my golang scripts for find/replace. i.e. golang is much faster and efficent. and xah-find.el act as wrapper, so you have word highlight and click on it jumps to the file location.
Emacs: xah-find.el, major update
- • file path is now quoted by 〈〉 instead of ❬❭ .
- • no longer highlight extraneous word. (1 per block by design)
- • when output file is reopened, it will syntax color. Pressing enter on path will jump to it. but pressing enter on occurrence will not. Solution pending.
- • when save to file is true, it will no longer print to message buffer for each write file operation. (because thousands of them is annoying and scroll off top message buffer content.)
most editors, use line number and column number to identify a cursor position. Emacs typically uses char position. Is there any other editor or compiler output report by char position or support goto nth char? e.g. M-x goto-char
name change. from xah-display-control-l-as-line to xah-show-formfeed-as-line
now run in background.
golang does not allow emacs formfeed U+000c ^L character
lol. golang does not allow emacs formfeed U+000c ^L character. pushing old school out. i was thinking it would, because old school. i guess progress is eventual. I was rather fond of using ^L in my code and text files
had big philosophy on it. ^_^ Emacs Form Feed (^L) Page Marker
Emacs: Xah Fly Keys now support Brazil Portuguese keyboard layout.
thanks to Nicolau Werneck nlw0
wow, Steve Yegge left Google
Steve Yegge left Google https://firstname.lastname@example.org/why-i-left-google-to-join-grab-86dfffc0be84
Steve Yegge, always have great insight. there is lots goodies here, but one thing is, mobile dev is hell, worse than web dev, and React Native is way to go. https://email@example.com/who-will-steal-android-from-google-af3622b6252e
Yegge is famous. Am a fan. I mentioned him a lot in past decade. here's my mentions:
- Emacs: Problems of the Scratch Buffer
- Criticism of Stevey Yegge's “Effective Emacs”
- Emacs Lisp Sucks Donkey Ass. Please Grow Emacs, Not External Tools
- Emacs Redisplay Internals, and JS Mode War
- Emacs: Why You Should Not Swap CapsLock and Control
- Testimonial on Xah's Emacs Tutorial
- Tips on Long Term Emacs Productivity
- Text Processing: Emacs Lisp vs Perl
- Emacs 23.2 Features (released 2010-05)
- Emacs Dev Inefficiency and Emacs Web 2.0?
- Modernization of Emacs: Simple Changes Emacs Should Adopt
- Syntax Coloring in Editors
- Steve Yegge's Google Platforms Rant
Grow Emacs, Not External Tools
it seems to me, emacs users have become more and more dumb, as seen on reddit over decade. it used to be, emacs users are the hardcore coders, hackers, of C et al. but now, like average IDE user who want stuff, like LSP, and lots packages, features, and that's ALL.
LSP, the Language Server Protocol, would kill emacs. With emacs lisp staying at 1990s cutting edge, and now LSP, emacs becomes a shell, like every other IDE. More will rely on LSP, cuz every other lang is 10 times better faster.
now when you start emacs, hundreds phone calls are made. “hey, Joe Block turned on his computer.” That's the cloud. Like amazon google apple, soon, they gonna decide when to wipe your disk. This began with the use-package auto-install fak.
fixed a bug. now
xah-find-replace-text-regex will prompt to ask for backup. Before, it always does. thx to imdic.
eshell Cannot have two processes in ‘*grep*’ at once.
a problem of eshell: “Cannot have two processes in ‘*grep*’ at once.”
to my patreons, thank you and notes https://www.patreon.com/posts/20816906
changed default file path regex prompt from html\' to html$. cuz $ is familiar and practically correct. emacs \' is annoying. people ask wtf is that.
emacs meetup at San Francisco, Saturday, Aug 18, 1 to 3 pm. https://www.meetup.com/Emacs-SF/events/253565625/
emacs, create link of word etymology
here's one of my helper command.
(defun xah-words-word-etymology-linkify () "Make the current word into a etymology reference link. Version 2018-08-16" (interactive) (let ($p1 $p2 $input $result) (if (use-region-p) (progn (setq $p1 (region-beginning)) (setq $p2 (region-end))) (progn (setq $p1 (line-beginning-position)) (setq $p2 (line-end-position)))) (setq $input (buffer-substring-no-properties $p1 $p2)) (setq $result (concat "etymology of <a href=\"http://www.etymonline.com/word/" $input "\">" $input "</a>")) (delete-region $p1 $p2) (insert $result)))
i've been using the above command for maybe 5 or more years for my “Wordy English” blog.
since i work in html raw, i have lots of these. the way i work in html is similar to most using org mode.
so if you are a org mode user, you can also easily create a command that generate links to etymology of the word under cursor. and you can press a button to look it up. and also publish it. (e.g. if you blog about literature stuff a lot)
emacs htmlize.el, not convert tab to spaces inside pre tag?
just submitted a bug report.
is it possible to not convert tab to spaces inside pre tag?
in golang, its a community convention to use tabs, enforced by the bundled tool gofmt. (and i think tabs are critical in makefile.)
I write tutorials. So my primary use of htmlize is to convert programing language source code to a htmlized form. With golang, this maybe be a minor problem. thanks.
golang is superb
kudos to Dominik Honnef for writing go-mode.el extremely well done. https://github.com/dominikh/go-mode.el
by the way am truly impressed by golang.
- easier to learn than python even ruby.
- almost C speed. e.g. ≻30 faster than python.
- can compile to binary. Give it to friend to run, no need install go.
- Best doc among languages. The cleanest lang spec doc i've read (comparable to Racket scheme lisp). And doc for packages are concise, clear, accurate, consistent, well organized.
- high level as scriping lang like ruby or python. (which is what i use it for.)
- Supports functional programing. Lambda. λ take λ and return λ. Nested λ, etc.
golang vs python 3 speed comparison https://benchmarksgame-team.pages.debian.net/benchmarksgame/faster/go-python3.html go is 50+ times faster there.
am starting my own tutorial. Golang Tutorial
scimax emacs kit for scientific computing and publishing
spend 3 hours today with @johnkitchin in a coffee shop! most wonderful experience. he showed me https://github.com/jkitchin/scimax , basically making org mode do scientific computation and publication. interactive computation in org mode, with ipython, math, LaTeX, plotting, bibliography management features.
pretty print in emacs lisp
discovered the package lisp/emacs-lisp/pp.el.gz
and it's written by Randal Schwartz, famous perl hacker.
;; Copyright (C) 1989, 1993, 2001-2018 Free Software Foundation, Inc. ;; Author: Randal Schwartz ;; Keywords: lisp
use it like this
(pp '(defun xah-copy-file-path (&optional @dir-path-only-p) "Copy the current buffer's file path or dired path to `kill-ring'. Result is full path. If `universal-argument' is called first, copy only the dir path. If in dired, copy the file/dir cursor is on, or marked files. If a buffer is not file and not dired, copy value of `default-directory' (which is usually the “current” dir when that buffer was created) URL `http://ergoemacs.org/emacs/emacs_copy_file_path.html' Version 2018-06-18" (interactive "P") (let (($fpath (if (string-equal major-mode 'dired-mode) (progn (let (($result (mapconcat 'identity (dired-get-marked-files) "\n"))) (if (equal (length $result) 0) (progn default-directory ) (progn $result)))) (if (buffer-file-name) (buffer-file-name) (expand-file-name default-directory))))) (kill-new (if @dir-path-only-p (progn (message "Directory copied: %s" (file-name-directory $fpath)) (file-name-directory $fpath)) (progn (message "File path copied: %s" $fpath) $fpath ))))) )
the output is like this
"(defun xah-copy-file-path (&optional @dir-path-only-p) \"Copy the current buffer's file path or dired path to `kill-ring'. Result is full path. If `universal-argument' is called first, copy only the dir path. If in dired, copy the file/dir cursor is on, or marked files. If a buffer is not file and not dired, copy value of `default-directory' (which is usually the “current” dir when that buffer was created) URL `http://ergoemacs.org/emacs/emacs_copy_file_path.html' Version 2018-06-18\" (interactive \"P\") (let (($fpath (if (string-equal major-mode 'dired-mode) (progn (let (($result (mapconcat 'identity (dired-get-marked-files) \"\\n\"))) (if (equal (length $result) 0) (progn default-directory) (progn $result)))) (if (buffer-file-name) (buffer-file-name) (expand-file-name default-directory))))) (kill-new (if @dir-path-only-p (progn (message \"Directory copied: %s\" (file-name-directory $fpath)) (file-name-directory $fpath)) (progn (message \"File path copied: %s\" $fpath) $fpath))))) "
2018-08-04 thanks to Bo Yao
i wonder if it is practical to use this to implement automatic formatting of lisp code.
See also: Emacs: Why I Don't Use paredit
updated code for
xah-insert-random-string. Now will use any A to Z, a to z, 0 to 9.
Before, it uses only lower case, and avoids some vowels etc that may look like other, e.g. 1 l, o 0 O.
code update. fixed a bug on
If you have a question, put $5 at patreon and message me.