Xah Emacs Blog
You, put $5 in my patreon. https://www.patreon.com/xahlee
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
emacs indentation problem and universal framework
emacs lisp. going to do a biggish job. write a tutorial for how to implement programing language indentation in major mode. and do it for my xah-js-mode.
it'll take about 6 hours.
emacs lisp. to write a indentation command, is a clean text processing task. given a text file and cursor position, you want to add certain tab or space in beginning of certain lines. Not trivial, but nor really difficult.
However, if you want to follow emacs convention, the task becomes somewhat more complicated. because emacs has a very stilted convention that's also half-assed. if you publish your mode, you basically have to follow this convention, else hacker types no welcome it.
emacs has 1 major problem. it tries to have a universal system, so if all major mode follows it, then users can make 1 config across all major modes. e.g. set up tab/space for indentation, indentation commands, comment, syntax coloring, completion, etc.
the problem is, some of these systems are really lousy. That's why you end up with each major mode doing its own way, or inventing complete new UI. Most notable is completion, indentation/tab/space setup.
Note, the “universal system” is modern jargon is Framework or API. However, in emacs lisp, they are not really that, because the entire elisp doesn't follow API mindset, partly by intention, cuz rms wants it to be “free coding”, or, fear if there's API, 3rd party will hijack.
2018-04 gonna have to get up and walk for an hour per day. Else my left hand is going to crippledom fast.
notes on today's emacs meetup Mountain View. 2018-07-28
today's emacs meetup was fun. https://www.meetup.com/Emacs-SF/events/252240839/attendees/
We met Jeff T, Michael W, Leslie L, Harry S, Arthur A G, David S, Huynh K, Gaurav J, and me Xah L.
Gaurav provided us with a super nice conf room with a view from 10th floor! and we had few nice light presentation on the spot!
emacs meetup SF has a github page https://github.com/Emacs-SF/
and i think @JaafarTrull keep notes on it. Not speaking for jeff or team, but i think we are looking for more lightning talks, or longer presentations. So if interested, get in touch with jeff.
Harry gave a short talk about using emacs with UI to “the best” dictionary, 1913 Webster's. you download a dict source file, a star dict command line UI, and a emacs UI wrapper. you can see setup at https://github.com/hrs/dotfiles/blob/master/emacs/.emacs.d/configuration.org#look-up-definitions-in-webster-1913
irreal wrote about using emacs with 1913 Webster dictionary at http://irreal.org/blog/?p=6546 am going to set it up myself. I'd love it. Yes, what dictionary you use matters.
am a dictionary nerd. I used to lookup words some 50 times a day, for 20 years. Still do 5 or so times daily now. You can read up what i have to say at American Heritage Dictionary vs Merriam Webster Collegiate btw, the worst dictionary is the one bundled with Mac.
For dictionaries, my ranking is:
- American Heritage.
- Merriem Webster UNABRAGED (weights a brick).
- 1913 Webster, WordNet, Google, wiktionary, are all rather lackluster, but each has its uses.
- Merriam Webster Collegiate, which is what you see everywhere and online, is the worst.
Well, the one bundled with Mac, which is “New Oxford American Dictionary”, is worser than worst. see American Heritage Dictionary vs New Oxford American Dictionary
by the way, if you want emacs commands to lookup any online dictionaries (or web search, function doc lookup etc), try xah-lookup.el Emacs: xah-lookup.el, Lookup the Web can setup to use emacs builtin browser eww
for next emacs meetup in Mountain View, i think am going to bring my Kinesis Advantage2 Keyboard Kinesis Advantage2 Keyboard Review so you guys can try it. it'd be fun.
another thing i learned from the meetup is, @JaafarTrull gave a lightening talk about emacs lsp mode. LSP is Language Server Protocol. It allows emacs to connect to server dedicated to parsing langs. So you get better completion etc due to real parser at server.
the hideousness of emacs lisp regex
wasted 1 hour debugging emacs lisp replace-regexp-in-string. the replacement string cannot be (match-string 1 var), must be "\\1"
and a reddit question
The Different Meaning of “closure”
see bottom there
elisp, nested dolist is a pain
ok, nested dolist is a pain in the ass. very hard to manage and edit. #emacs #lisp
in Wolfram Language, loop function usually accept a optional predicate function, so that if it returns true, the loop exits. This is much better than elisp's catch/throw.
if you want to understand Wolfram Language's such exit, search online for “NestWhile” https://reference.wolfram.com/language/ref/NestWhile.html
minor update. Thanks to George Jones.
emacs keyboard used in 70s and 80s
posted to reddit.
hi guys, am trying to get an overview of keyboards used by emacs people during 70s and 80s. If you been there, could you list the keyboards/terminal you used, and year period, before 1990, as much as you can remember?
if you been there, help me out. thanks.
What Keyboards Are Used for Emacs in 1970 and 1980s?
new version of emacs tutorial is out
new version is sent out to all who got it after 2014, or those responded to previous update.
if you should've got it but didn't , email me.
there are some of you who bought it twice, or otherwise donated extra. Thank you very much.
autoload and require
answer to reddit question.
autoload is more for interactive use purposes.
require is for loading libs.
so if you are writing lisp code and need another package, always use
if you are setting up init file, best to set up
autoload when possible. Because that way, it saves startup time. The file is loaded only when user actually calls it. Best example of such are programing language modes.
List of Emacs Starter Kits (minor update)
emacs default key
my reddit post
Perhaps, look at it this way:
most emacs users use emacs default keys because it's the default. This is same with qwerty vs dvorak situation, or any tech. It takes quite some effort to change things out of ordinary. e.g. first one must be aware there are alternatives. This also rules out most newbies for not using default key.
for those who use spacemacs and change it to emacs default key, probably because, they already have experience with emacs. The default keys are burned to muscle memory, which is hard and painful to change.
default key has other advantages other than habit. e.g. dvorak layout is more efficient, but everytime you goto library, or use other computer, it's a problem. And other people can't type on your keyboard. This also applies to PC keyboard vs those fancy ergo ones such as ergodox.
another advantage of default is that it's the “official”. As with most other things, you want to stick to official. Unless one really learned otherwise, such as by words of mouth and established a trust on X.
vi is more popular simply because vi is bundled with unixes. Emacs require install. This is still true today on linuxes.
people switch away from default mostly due to need. e.g. those who got hand pain. Those who have interest in efficiency. (which may be the same reason that drew them into emacs in the first place)
i used emacs default keys 100% for the first 6 years of my emacs life.
emacs meetup in Mountain View, CA!
mark your calendar.
and several recent articles about lisp the programing language Xah Programing Blog
lisp machine keyboards
several recent articles photos about lisp machine keyboards Xah keyboard Blog
updated. Now includes literal expression for hash table.
updated. fixed emacs 26 change of
ucs-name. now, selection such as RIGHTWARDS ARROW works again.
emacs 26 elisp change. ucs-names is now a hashtable
2018-07-09 emacs 26 change.
ucs-names was alist, now it's hash table.
update all your code
you can use this wrapper:
(defun xah-math-input--name-to-codepoint (@name) "Returns integer that's the codepoint of Unicode char named @name (string). Version 2018-07-09" (interactive) (if (version<= "26" emacs-version) (gethash @name (ucs-names)) (assoc-string @name (ucs-names) t)))
elisp name “my/” prefix, slash or hyphen?
as many said, it's a convention. This convention, is not official though. Official gnu emacs stance is to use hyphen.
technically, slash is slightly better, as it distinguishes name space purpose from word separator. However, because it's not gnu convention, so it has problems. eg say you dev all your packages with slash. But one day your package becomes popular, and you are considering to assign paper to be part of gnu emacs. Then, you got the problem of changing all your names, thus break all init out there...
real solution, is to get FSF emacs team to introduce namespace. It is not hard to do, if one do not consider 100% backward compatibility to 30 years back, but typically they want that, for reasons in my opinion is not practical. Among other social problems of gnu emacs dev. Major one is that in the fsf culture, no one really takes a leader role to get things going. It's arguments and arguments, and rms now and then say things by hegemony. Technically he should not have power over any non-political emacs issues, as that is understood to be the current maintainer. But in reality, far from it.
besides the slash vs hyphen issue, there are others, e.g. using question mark for all predicate functions. (i.e. function that returns true/false). The question mark is superior, and is the convention in scheme/racket lisp, ruby, clojure. Emacs lisp tradition is p, however, it's quite lousy, as lots functions end in p but is not predicate, and for predicate, some are “-p” some just “p”. Again, we have the backward compatibility vs progress problem. Note, many popular packages on melpa, use the question mark convention. e.g. the package “dash”.
minor fix. now if
universal-argument is called before, and there's selection, the selection is deleted only after the choice of format is made. (before, it delete selection first, then prompt choices, which is not good, because sometimes you want to see what's the format used before you chose.)
better doc. also, don't move cursor to end of buffer.
emacs highlight cursor line
global-hl-line-mode. does anyone uses it?
emacs indium https://github.com/NicolasPetton/Indium
this seems to be the upcoming best emacs package set for web dev.
thanks to https://twitter.com/ebanders for the tip
one extreme complex fak. you can't compile jsx with TypeScript unless you let TypeScript know react js file paths. but now you can't unless they have .ts suffix. but if you change them to .ts , faking 1 thing leads to 10 more complexity.
- draft support of jsx syntax highlight.
- support .jsx file suffix.
xah TypeScript mode. https://github.com/xahlee/xah-typescript-mode
also now support tsx file extension. beta
xah-run-current-file now support .tsx (TypeScript + react + jsx)
emacs meetup SF Bay Area, in Oakland, July 7th
next emacs meetup SF Bay Area, in Oakland, July 7th. https://www.meetup.com/Emacs-SF/events/251665595/ mark it in org mode todo! (and i think there's one In Mountain View after, which i'll attend)
again, you can host your own emacs meetup in your area. you can use the site https://www.meetup.com/
to find the date of meeup xyz, i usually go to the site, login, then you can search.
emacs muscle exercise. extract a unicode html table
goto http://unicode.org/emoji/charts/text-style.html there are 3 columns. Extract them so that you have 3 lines of emoji in plain text. (line can be paragraph or list) use any means in emacs or elisp. Or, bonus if you can do it easier outside of emacs. #unicode
long lines in emacs true pain
true pain in emacs. sometimes you copy paste a long line into emacs by mistake. e.g. html source of http://unicode.org/emoji/charts/text-style.html then it takes 5 fkg minutes to get out.
ways to avoid shift key
here's the solution i use to avoid Shift key
might try turn on Sticky key in your operating system. (usually under accessibility/disabled-help)
i've tried to ban it completely. Ban Shift Key
currently i use
Emacs: Upcase Sentences
Emacs: Change to Title Case
Emacs: Toggle Letter Case
for most of my upcase needs.
for paren/bracket, i use lead sequence 【Space e t】 (dvorak) in xah-fly-keys. Emacs: Insert Brackets by Pair
if you are using ergodox, keyboardio, etc that has programable firmware, you can set a thumb key (such as Space Enter ⌫ Backspace) to double as Shift when held down. Amir Rajan suggested this:
emacs hangout, Thursday, 28 June, 6pm San Francisco time
please join us. cc @sachac @johnkitchin @howardabrams few persons i love to see, and many others (you!), please do join, hosted by the great @JaafarTrull i met in last hangout and SF meetup.
jeff trull announcement on twitter https://twitter.com/JaafarTrull/status/1011810892206358528
twitter comment https://twitter.com/ErgoEmacs/status/1011818010112217088
alias outline mode to org mode
(defalias 'outline-mode 'org-mode)
(actually that didn't work for some reason. i haven't had time to find out why)
annoying outline, screws xah-fly-keys. and, by the way, itself is useless. org-mode is superset + easier keys.
emacs quiz. print string of unicode variation selectors
quick, use emacs to print a string containing U+FE0E to U+FE0F. you can use any emacs ways, or write a emacs lisp function. tips:
now you can get my tutorial by paying me via amazon egift card.
emacs + 3 huge screen + eye tracking + ergodox
streaming live now. https://www.twitch.tv/amirrajan
writing a major mode, free form or not
currently fret about whether my xah html mode should be based on: ① fundamental-mode ② #emacs 26 mhtml mode. With ①, am free to have it however i like. simplicity. but it won't syntax color html from the wild “correctly”. Though, that's not that important.
problem of basing on emacs html-mode or the new mhtml-mode is that, the code becomes EXTREMELY complex. you got 3k lines mucking under it in sgml mode. you don't have control or flexibility, unless u understand those 3k lines
xah-html-mode itself is 3.5k lines. They are text transformation code. Only 0.2k lines are about syntax coloring.
base programing language major mode on prog-mode?
in emacs lisp, it's common to hear recommendation that programing language mode should be based on prog-mode. after looking at the code of prog-mode, am not sure it's a very a good idea.
I think there's not that much benefit for doing so. Meanwhile, it limits flexibility of major mode design. Also, just a tiny bit. So overall, either way, i think it's not that useful.
Elisp: Char data type (new page on its own)
Elisp: Syntax Table Tutorial (updated)
emacs abbrev video tutorial
perm url emacs abbrev demo 2018-06-12 📺
got a comment. “Nothing works in emacs26-nox”. about my xah-fly-keys. Sometimes, it's really annoying to do open source.
Emacs: Xah Fly Keys Customization, added a section on how to Change Command Mode Key Depending on Major Mode
starting to casually write about emacs 26 new features.
am starting to casually write about emacs 26 new features.
here's the news file Emacs 26.1 New Features (released 2018-06)
am going to edit it as i read it.
one problem of emacs is that its features file, is cryptic. i've used emacs for 20 years now and am reasonable expert at elisp, but half of “NEWS” file i don't understand, without spending lots time digging into each. Same for others who've used emacs for 20+ years.
the problem, is not because oh emacs is so big and powerful. That's what you like to hear. The problem, is actually the writing, and the mind set of the devs. It is written, in a style that makes it incomprehensible.
This is similar to why academic papers (e.g. on computer science, programing language research) are filled with jargons, UNNECESSARILY. Academic papers are that way because, its main function is not to distribute knowledge, but, as part of system to promote the writers, among peers. The culture induced the style. Similar for government bureaucracy papers such as DMV.
for emacs, the problem is, emacs dev has this cult of it being the supreme, lisp machine, oldest, etc. So, the writing style sprung from a mind set of that. Part arrogance, part 30 years old jargons, and part inept geekdom who are unable to communicate to the public.
however, when you read emacs doc, the emacs folks want you to think, it's incomprehensible to you because emacs is extremely advanced.
and by the way, emacs calls its “release notes” as “NEWS”. Another addition to incomprehensibleness.
get emacs 26
now emacs 26 is out. To download prebuilt for Mac, Windows, linux, see
emacs 26.1 window bar transparent problem
problem due to desktop-saved-frameset in desktop save mode file. i guess there's some change between emacs 26.0 and 26.1 causing it.
- open your
~/.emacs.d/.emacs.desktoplook for the first line containing
(setq desktop-saved-frameset …). comment out that line.
desktop-save-modeto turn it off.
- restart emacs.
2018-06-07 addendum: apparently, that does not fix it. When you have
on and restart ,
the problem comes back. it seems, i have some init that cause emacs to
save something bad about frame config to the desktop-save-mode file. But
note, this did not happen in emacs 26.0.91.
am going to San Francisco emacs meetup
woot, am going to emacs meetup this Saturday. Sign up, let's meet https://www.meetup.com/Emacs-SF/events/251056510/ … PS if you are in Mountain View, San Jose area, a friend can pick us up. Else we go by train! pm/email me
reddit announcement https://www.reddit.com/r/emacs/comments/8oyh4a/lets_meet_up_emacs_sf_saturday/
feel free to send me modified js code for other layouts.
Xah Emacs Packages (minor update)
added a new command
goslin emacs in Google Hangout!
emacs Google Hangout
hi everyone, today we have some Google Hangout at 6 pm (California Time), random chat about emacs. if you feel like it, hop on. I think i'll post the google hangout url 10 min before. (haven't done this before)
you can learn about google hangout at https://hangouts.google.com/ i think you need a google/gmail account.
this is informal, of course. Am ackward at social events, but some random emacs chat could be fun. Haven't done this before. Hope the video tech side will go smooth. Drop in 5 min or so to say hi is good. Gotta try it.
so far, we have 4 people counting me. it's gonna be fun.
if you like to join, best to email me email@example.com with your email, so i can send you a invite from google calendar. In case i was not able to find out how to do public hangout, then it's just those of use who have invite.
twitter thread here https://twitter.com/ErgoEmacs/status/1002599034664570880
If you have a question, put $5 at patreon and message me.