Xah Emacs Blog Archive 2018-08

is emacs lisp best for text processing?

elisp hole 2018-08-31 9a9b0
emacs lisp hole 2018-08-31

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: (1) no literal quote. If your find string is a snippet of regex, spend 10 min to manually quote it first. (2) elisp regex sucks donkey ass. (3) 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 (example: 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, example: 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 (example: 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: (1) add a line below current. (2) move cursor there. (3) 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 emacs open-line behavior).

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 xah-insert-space-before before. )

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

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.

ELisp: Write grep

Problems of grep in Emacs

Emacs: Xah Find Replace (xah-find.el)

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

Emacs: Xah Find Replace (xah-find.el)

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

Emacs: Form Feed ^L (Page Break)

name change. from xah-display-control-l-as-line to xah-show-formfeed-as-line

Emacs: Run Current File 🚀

now run in background.

ELisp: Get Buffer String

golang does not allow emacs formfeed U+000c ^L character

formfeed golang 2018-08-28 fe29e
formfeed golang 2018-08-28 fe29e

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 Problems

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://steve-yegge.medium.com/why-i-left-google-to-join-grab-86dfffc0be84

steve yegge left google 2018-01 72642
Steve Yegge left Google

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://steve-yegge.medium.com/who-will-steal-android-from-google-af3622b6252e

Yegge wrote js2-mode, which contains real-time JavaScript code validation. And ejacs mode, which contains JavaScript compiler, in emacs lisp.

Yegge is famous. Am a fan. I mentioned him a lot in past decade. here's my mentions:

  1. Emacs: Problems of the Scratch Buffer
  2. Criticism of Stevey Yegge's Effective Emacs
  3. Language Server Protocol (LSP) Kills Emacs
  4. Emacs: JavaScript Mode War (2008)
  5. Emacs Lisp vs JavaScript
  6. Emacs: Why You Should Not Swap CapsLock and Control
  7. Testimonial on Xah Emacs Tutorial
  8. Tips on Long Term Emacs Productivity
  9. Text Processing: Emacs Lisp vs Perl
  10. Emacs 23.2 (Released 2010-05)
  11. Emacs Dev Inefficiency and Emacs Web 2.0? (2010)
  12. Emacs Modernization: Simple Changes Emacs Should Adopt
  13. Syntax Coloring Compared: Emacs, Vim, Atom, Sublime, Visual Studio, WebStorm
  14. 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 fuck.

Language Server Protocol (LSP) Kills Emacs

Emacs: Xah Find Replace (xah-find.el)

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.”

Emacs: eshell

Emacs Init: Show Line Numbers

to my patreons, thank you and notes https://www.patreon.com/posts/20816906

Emacs: Xah Find Replace (xah-find.el)

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"
  (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. (example: 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.

Emacs: What is Hook

Emacs Init: Set Default Major Mode

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.

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

Emacs: Spaces to New Lines 🚀

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

'(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://xahlee.info/emacs/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://xahlee.info/emacs/emacs/emacs_copy_file_path.html' Version 2018-06-18\"
  (interactive \"P\")
            (string-equal major-mode 'dired-mode)
                    (mapconcat 'identity
                     (length $result)
                    (progn default-directory)
                  (progn $result))))
            (expand-file-name default-directory)))))
     (if @dir-path-only-p
           (message \"Directory copied: %s\"
                    (file-name-directory $fpath))
           (file-name-directory $fpath))
         (message \"File path copied: %s\" $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 Automatic Formatting Emacs Lisp Code

See also: Emacs: Why I Don't Use paredit

Emacs: Insert Random Number or String 🚀

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, example: 1 l, o 0 O.

Emacs: Convert Chinese/Japanese Full-Width/Half-Width Punctuations 🚀

code update. fixed a bug on xah-convert-fullwidth-chars