Xah Emacs Blog

Emacs: Move Cursor to Beginning of Line/Paragraph code complete rewrite. Now does not depend on another function.

Emacs: Upcase Sentences (new command)

Emacs: Delete Backward Char or Bracket Text (now supports ascii quotes.)

emacs logo poll 2016 12 27
Poll result: do you like emacs logo in the splash screen? https://twitter.com/ErgoEmacs/status/813938274766966784

all syntax coloring on the site are redone, based on the latest version of Emacs: Xah Emacs Lisp Mode (that is, if you use xah-elisp-mode, the coloring in emacs buffer would be the same as on the website.)

notable is that the coloring are based on the “types” of symbol, as detailed here: Meaning of Lisp List, Function Type, and Syntax Coloring

still to do, is the tooltips for variables.

Emacs: Paste or Paste Previous (bug fix)

Meaning of Lisp List, Function Type, and Syntax Coloring

poll: 'NOERROR vs "NOERROR"

new poll, 'NOERROR vs "NOERROR". vote at

Emacs Lisp: Symbol vs String for non-nil Values

Emacs Lisp: Find Matching Bracket Character (new article)

Emacs: Quote Lines (code update. Now delimiters are added by skipping whitespaces)

emacs symbols obarray list 2017 01 06
emacs run as --batch, not loading anything, there are 15305 symbols in obarray. normally, it's 45k to 80k symbols or more, depending number of packages loaded.

Programing Language: Syntactic and Semantic Difference of Map Function

How Many Keyboard Shortcuts Are There

new tooltips

the tooltips are regenerated, from emacs 25.1

now ALL functions mentioned in elisp manual have tooltips. try (info "(elisp) Point") and Emacs Lisp: What's Function. (goto the page, hover mouse over a function name, or touch it in phone/tablet.)

though, it turns out, quite a lot commonly used functions are not in elisp manual. For example, eval-last-sexp, ielm, describe-function.

Am working on that. Also, variable will also have tooltip soon.

Emacs Lisp: What's Function (major rewrite.)

i think sometime between 2013 to 2016, defun is moved from implemented in C to implemented in elisp.

;; test if defun is implemented in C
(subrp (symbol-function 'defun))

#emacs ido-completing-read can handle 81k items no problem

Emacs: Delete Backward Char or Bracket Text (new command.)

Emacs: Paste or Paste Previous (new command)

Emacs: Xah Emacs Lisp Mode (Major update. Now, ALL elisp symbols in elisp manual are colored, and are colored by their technical type: function, special form, macro, command, user option, variable. )

Emacs: Change to Title Case (minor code update. fixed “can'T” to “can't”)

List of Emacs Starter Kits

new one is scimax, for scientist/engineer for reproducible research and publishing. Focus on LaTeX and org-mode.

Emacs: View Info Page (minor update; new screenshot)

emacs sign 2016 12 31
〔image source 2016-12-31 https://twitter.com/murphy_karasu/status/815133850489626624

vim fitness vs M-x Donuts

Emacs Lisp: What's Symbol. understand lisp symbols. (complete rewrite)

the emacs manual mirrored on my site, is also updated to version 25.1. see (info "(emacs) index")

though, i rarely link to it. Because, if you want to learn emacs, there are quite a lot approaches that's more efficient than reading emacs manual.

i recommend:

  1. Just use emacs. Use and use, profusely. When you have a issue, seek answer, on the web, on xah tutorial, or ask stackoverflow, reddit.
  2. When you have leisure time, start learning emacs lisp.
  3. To learn emacs lisp, my advice is just to read my elisp tutorial. Practical Emacs Lisp. There's not much material elsewhere.
  4. While you are learning elisp, write helpful commands you need. And in the process, you'll have questions, then, seek answer.
  5. You will start to read parts of elisp manual now and then. This is real progress, making you understand emacs.
  6. Soon, you'll want to write a non-trivial package. This is when, you start want to read the elisp manual thoroughly.

the how to write a emacs major mode series, all pages have been updated. see Emacs, How to Write Major Mode, Panel Index

Emacs Lisp: How to Define Face (new)

Emacs: Color Nested Brackets

Emacs: Quote Lines (new command)

how often do you change your emacs init?

vote at

reddit: evil mode vs emacs keys

https://www.reddit.com/r/emacs/comments/5k3rda/evil_vs_default_keybindings_comparison/

i've researched this issue a lot.

about your specific list, like /r/angelic_sedition, i think some items can be made more precise, while some items may not be relevant without a precise goal. For example, your 3rd item about “harder to create specific keybinding…”. Is your goal/question about emacs, or about generic context with a programable keyboard such as ergodox? They have different answers. For example, if it's about in emacs, best is to avoid defining a key in keyboard firmware to send a chord that emacs uses. Better is just to directly define a keybinding in emacs. (unless there's some other issue, doing this as a workaround)

given a very flexible programable keyboard such as ergodox, and you want to program the keys, there's the choice of optimizing it for emacs, or optimizing for general use outside of emacs too. Or, somewhere in the middle ground. It depends on how much your time is spend in emacs. (for me, i optimize for emacs some 90%, because I almost type everything in emacs than paste it somewhere.) (if you optimize for emacs, there's of course also the question what key system you use, e.g. evil, or emacs default, or other.)

For general question about programing keyboard firmware for utmost efficiency, Gergely Nagy wrote a great article. See

Multi-purpose keys, and a case for small keyboards By Gergely Nagy. @ https://asylum.madhouse-project.org/blog/2016/10/15/multi-purpose-keys/

Gergely Nagy also programed several open source keyboard firmware. I'd recommend his stuff. e.g. https://algernon.github.io/Akela/

in general, modal mode will save you key strokes, all thing considered (including the need to press a key to switch mode), i estimate that modal mode saves you about 10% count of key press.

also, note that vim modal mode is not efficiently designed. The key choices are mostly historical, not based on command frequency.

emacs default keys are also historical.

Lastly, i'd say, if you want the most efficient modal mode based on command frequency statistics and ergonomics, might try Emacs: Xah Fly Keys you want the same but based on chords, then ergoemacs-mode http://ergoemacs.github.io/. Evil mode is great in that it is fairly efficient, and have the advantage of also muscle memory of using vim, make it a good choice on wide range of computers one may need to type on without config.

new. on melpa by request. xah-reformat-code (20161216.1859) --- commands to reformat source code. https://melpa.org/#/xah-reformat-code

explanation at Emacs: Reformat Lines for Source Code

Emacs: Rename File from Space to Hyphen/Underscore (bug fix. Now will also rename the buffer if open.)

elisp manual updated

the gnu emacs lisp manual mirror on my site is updated to emacs version 25.1. See (info "(elisp) index")

the gnu emacs manual html version CSS has improved in recent years. In 2013, it's still 1999 era html. Now it's modern looking.

Emacs: Using Eww Web Browser (new screenshot)

why a file variable “lexical-binding: t” is better than a special function “lexical-let”?

emacs skeeto (chris wellons, author of elfeed, skewer, etc) explains advantages and workings of lexical binding really well.

The advantages of lexical-binding:

  1. It has a measurable performance advantage. For example, variable accesses are simple array loads (stack-ref opcodes) rather than global variable lookups (varref opcodes), and the compiler can optimize away lexical variables.
  2. It's less buggy, since local variables aren't exposed to callees.
  3. The compiler can perform additional checks and will provide additional warnings.
  4. Closures.
  5. It applies not just to let, but to all forms that create local bindings, such as function parameters, condition-case, and any macros that expand to let.

[from https://www.reddit.com/r/emacs/comments/5j9qgz/lexicalbinding_t_vs_lexicallet/dbevk2j/]

He then proceed to explain in terms of bytecode. Be sure to read it in the link above.

One of the reason, that lexical binding applies to not just let but also function parameters, condition-case etc, convienced me why file level declaration is the right choice, with respect to language design.

“lexical-binding: t” vs “lexical-let”?

What's the reason of introducing file variable “lexical-binding: t” instead of a macro/special-function such as “lexical-let”?

emacs lisp doc tack symbol
emacs lisp doc use tack symbol

nice to see math symbol used in emacs.

the symbol used is (U+22A3: LEFT TACK)

See also: Unicode Math Symbols ∑ ∞ ∫ π ∈ ℝ²

emacs lisp toothpicktitus 2016
emacs lisp toothpicktitus

emacs lisp lexical scope, and the problem of bandwagon

updated all my packages to use lexical scope.

you can see all my packages at Xah Emacs Packages Panel Index

Here's functions updated that has a tutorial page:

to declare lexical binding, add this to the first line of your elisp file:

;;; xyz.el --- xyz does xyz. -*- coding: utf-8; lexical-binding: t; -*-

if your elisp package uses lexical binding, you also need to declare this:

;; Package-Requires: ((emacs "24.1"))

That's the convention of emacs version requirement declaration used by melpa package repository.

lexical binding is introduced in emacs 24.1 (24.4. is released in 2014-10)

lexical binding makes elisp code run slightly faster, and elisp compiler will find more errors, such as unused local variable. And pave the way for the future of elisp. (e.g. concurrency)

〔➤see Emacs: Byte Compile Elisp Files

one interesting finding is that this form of function call:

((lambda (x) (+ x 1)) 3)

is deprecated. You should do:

(funcall (lambda (x) (+ x 1)) 3)

but actually, the funcall form is inferior. It introduces a new function. Most other langs don't need it. For example, scheme lisp, clojure, JavaScript, Wolfram Language and most other modern languages can directly call function in the form of normal function call, simply replace the function name by a function expression.

For example,

the problem with elisp is that a function doesn't just return a function. Instead, elisp has symbols, and a symbol has function cell and value cell. The value cell could potentially contain another symbol whose value is another function (i.e. symbol with function cell). In other words, a function isn't just a function, but could also be a variable, and the value of the variable could also be a function. So when you have (f arg), that f could be a function itself, or could be a variable that holds a function. This is the same problem with Common Lisp. In the case of ((lambda …) arg), it works, but i suppose is deprecated because in general won't work with arbitrary expression for the head.

another thing i never understood, is why emacs dev introduced a directive for lexical binding. I rather prefer a new function/macro, such as “lexical-let”.

by the way, if you write code properly, for example, always use function without side-effect, and always use local variable, then you don't really need lexical binding. It has no effect.

my stance was, am never going to add that lexical binding directive. It really should be part of the language. If it is “lexical-let”, then i'd be happy to use it. But the thing is, usually you can't fight a trend in large society. When something becomes popular, that everyone is doing it, even if it is a stupid one, you can't simply stand aloof and to keep yourself of some superior way, because, when everyone is doing it, it has an effect on many other things and future change. Your “incompatible” superior way gradually gets in the way as things evolve with the inferior system. Example of such as QWERTY keyboard layout, unix, programing conventions, writing convention. For elisp lexical binding, it is the way things are and elisp is moving forward. If your code does not use such directive, your code will not be able to reap whatever advantages coming to it, will be left behind, and most coder don't understand will simply think your code is stupid.

js2-mode error highlight problem

emacs js2 mode syntax error highlight problem 2016 12 15
emacs js2 mode syntax error highlight problem 2016-12-15

js2-mode got this annoying syntax error highlight problem.

it sticks with the old school style of requiring semicolon. But thousands packages on npm follows new school style of no semicolon.

〔➤see JavaScript: Semicolon Rules

if you want js2-mode features, a solution is the derivative js3-mode.

ido-separator obsolete

in emacs 25.1, the variable ido-separator is now obsolete. Replaced by a element in ido-decorations

for new elisp code to config, see updated:

Emacs: Switch Buffer

emacs lisp completion problem

start emacs with -Q, open a new buffer, M-x emacs-lisp-mode, type defu, press C-M-i, do you get “defun” or “defun-”?

vote here:

poll results:

emacs lisp completion 2016 12 01 poll gplus emacs lisp completion 2016 12 01 poll twitter

this is quite odd. I remember it was working.

but apparently, about half of people, they don't get proper completion. (nor me. I'm on emacs 25.1.1)

it's interesting because:

if you did get the correct behavior, did you actually start emacs with -Q? What emacs version are you using? (post comment on twitter or Google Plus.)

emacs, real auto save, and auto save when you call M-x

there's a package called real-auto-save, on melpa. It does “real” save periodically.

i was temped to write my own, but my current solution is that in Emacs: Xah Fly Keys , a modal key mode, everytime i switch to command mode, it also does a save.

you could do the same. For example, everytimes you call M-x, it does a save then M-x. Just write a short elisp command wrapper like “save-buffer-then-execute-extended-command”. If you want and don't know how, ask, many or i can show you how.

reddit comment at https://www.reddit.com/r/emacs/comments/5h7k1r/undo_lost_hours_of_work/dazcpjq/

reading emacs manual vs elisp manual?

if you want to read emacs manual and want to be efficient in learning, read the elisp manual instead.

because emacs really is just lisp interpreter with a user interface. ie the GUI or TUI in terminal

this emacs lisp interpreter environment, is beyond repl. You can eval any buffer, or code, anytime, as in a interactive notebook.

emacs has a repl on top of emacs lisp environment, M-x ielm

〔➤see How to Evaluate Emacs Lisp Code

elisp manual is hard to read. You have to go thru hundred pages just to cover elisp basics. GNU Emacs Lisp Reference Manual (info "(elisp) index")

the hundred pages of elisp manual is summarized just by 10 pages here Emacs Lisp Basics

Emacs: Xah Math Input Mode now can be buffer local or global. Emacs: Xah Math Input Mode

Emacs: Xah Emacs Lisp Mode Much update in past months. If you had problem with company mode, now it's fixed.

just tried Emacs: Xah Fly Keys on emacs 24.5.1 started with -Q. runs smoothly

Emacs 25.1.1 Change: emacs-lisp-mode extracted from lisp-mode to elisp-mode.el

the emacs dumper dispute

another controversy in emacs. https://www.reddit.com/r/emacs/comments/5frpp4/the_emacs_dumper_dispute/

Emacs Redisplay Internals, and JS Mode War

Emacs: Move Cursor to Bracket/Quote

updated code. Now xah-goto-matching-bracket will jump to matching quote too. And fixed a bug in xah-forward-quote-smart.

gnu emacs disabled a feature for Mac OS X so that it isn't better than linux version of emacs

gnu emacs removed code for color emoji feature in Mac OS X. see

Bye Bye Emojis: Emacs Hates MacOS By Sebastian Wiesner. @ http://www.lunaryorn.com/posts/bye-bye-emojis-emacs-hates-macos.html

On the OS X Cocoa (“Nextstep”) port, multicolor font (such as color emoji) display is disabled. … This will be enabled again once it is also implemented in Emacs on free operating systems.

reddit discussion https://www.reddit.com/r/emacs/comments/5e3xpu/emojis_in_emacs_intentionally_disabled_for_osx/

see what the current leader jwiegley has to say, in comment above.

jwiegley wrote:

This decision wasn't something “I approved of”, in the sense you're thinking. I do use a Mac, and I do miss my color emojis.

GNU Emacs is a project of the Free Software Foundation, and when they deem an issue as relating to their political agenda, it trumps the technical purview of the project maintainer. I keep Emacs going from a software point of view; they keep the FSF going as a movement.

If RMS says that such a change relates to freedom, I can either acquiesce or walk away. I didn't think color emojis were important enough to walk away. The gcc/clang dispute was part of the reason the last maintainer walked away.

It's a free project. If a group of people is willing to put in the effort, you could fork Emacs and make it into something better, freed from the FSF's policies. Until that happens, expecting them to change by writing blog posts, or commenting on Reddit, is not going to have any effect whatsoever.

by the way, it has always been like that. Every few years, major things like this happen got into news.

See also: GNU Emacs and XEmacs Schism

Emacs: Move Cursor to Bracket/Quote. new command xah-forward-quote-smart.

Emacs: 1 Key to Copy/Paste from Register

after a decade of back and forth about using this command vs copy-to-register, i think this is far better.

Emacs: Spell Checking

Emacs: Cycle Replace Space Hyphen Underscore (more code update. Now works inside parenthesis or bracket if is.)

keyboard efficiency tip: never mouse aim to close tab

keyboard efficiency tip: never mouse aim to close tab. too much effort. Middle click tab also takes aim. Set Pause key to close tab. Or, F13.

also, set F11 F12 to switch prev/next tab. Make use of all your Function Keys F1 F2…

see how to here: What's the Use of Function Keys F1 F2…?

in emacs, do the same. close buffer, next/prev user buffer, all single, one, key.

when kill buffer, stop emacs from confirming. also, a key to reopen last closed. see how to here: Emacs: Open Last Closed File

command to switch to Next/Previous User Buffer. Skipping scratch, info, shell out, etc buffers. Emacs: Next/Previous User Buffer

if you have a numpad, best is to set keys / * - to prev buffer, next buffer, close buffer. here's how: Emacs: Bind Number Pad Keys

Emacs Lisp: Some and Every

Emacs: Change Brackets () {} [] in Region (rewrite code. Now better code, also highlight changed places.)

emacs abbrev setup: using emacs commands vs using elisp code

after trying to use emacs abbrev commands to build list of abbrevs for a year, don't like it. Am reverting back to using elisp code for abbrev in my emacs init.

The advantage of just following emacs abbrev commands to create edit save abbrev is that, you have a tally of how many times you used each abbre. Sounds useful, but after 3 months, i find that the info isn't useful at all. I find that just a handful of abbrev i use daily, but i still want the rest abbrevs. The idea that i'll modify my abbrev based on the statistics of usage, didn't work out.

But mostly, the problem with following emacs abbrev command to create edit save abbrev is that, you have less control.

with abbrev as elisp code in my init file, i can control the regex used, the expansion function, the hook after expansion, for each abbrev. And, i can just edit it as easily.

Compare, using emacs abbrev commands: Emacs: Abbrev Mode Tutorial vs using elisp code Emacs Lisp: Create Abbrev and Templates for Major Mode

algorithm problem, matching cups and spoon

elisp problem lines and seats 2016-11-02
algorithm problem, matching cups and spoon 2016-11-02

the difference a language makes

elisp while loop vs dolist
elisp while loop vs dolist

Emacs Lisp: Overlay Highlighting

Apple MacBook Touch Bar. The design of the new MacBook touch bar, and what it means to programers.

Emacs: Cycle Replace Space Hyphen Underscore (updated code. Now will work on inside string quote, if cursor is inside a quote or bracket.)

emacs 25.1 feature. If you open a image, now it scales to fit in the window.

the damage by the hacker types of programers about line formatting.

Emacs: Why I Don't Use paredit#comment-2968350605

Emacs: Toggle Comment Current Line (on its own page. updated code.)

emacs M-TAB key poll

emacs meta tab key poll 2016 10 25 twitter emacs meta tab key poll 2016 10 25 google plus
#emacs lang major mode standard key for completion is M-TAB conflict OS Alt+Tab or Cmb+Tab. What do YOU do?

Emacs Lisp: How to Write Keyword Completion Command (minor update)

emacs info code red

emacs info code red
emacs info code red

make it red. glorious red.

〔➤see Emacs's Customization Tutorial

Emacs Lisp: Create Abbrev and Templates for Major Mode (tutorial complete.)

next tutorial in writing a major mode is indentation.

mouse hover tooltip function doc

the mouse hover tooltip now has better background color, and the iPad bug is fixed. You can close the bubble by clicking on it.

for example, goto this page, hover over a elisp function name. On tablet or phone, click it. Emacs Lisp Basics

The Glory of a Real Hacker: Ann Arbor Ambassador 60 Terminal

Ann Arbor Ambassador 60 Terminal By jwz. @ https://www.jwz.org/blog/2016/10/export-termaaa-60/

emacs history must read.

Coding Convention? Burn It.

Linus in “Linux kernel coding style” said:

“First off, I'd suggest printing out a copy of the GNU coding standards, and NOT read it. Burn them, it's a great symbolic gesture.”

from reddit, on emacs coding convention. https://www.reddit.com/r/emacs/comments/585osx/emacs_lisp_style_guide/d906u1j

That's a good point. But on a separate note, to a lesser degree, programer's practice of coding style, may be questionable.

Google has many coding styles, including python, HTML, and even Common Lisp. Its python style guide does not necessary agree with Guido's.

Many coding style includes name format convention such as camelCase vs pot_hole_case, do we actually have scientific data about these matters? (there's a couple, but not trust worthy.)

the coding styles may serve more of a purpose of bounding a particular community.

The rules given by bbatsov (i assume community driven) isn't followed by one of the most popular package on MELPA. For example, dash.el ends predicate function with a question mark.

also, gnu emacs suggest cutting lines to 70 char per line in doc. This is not a good convention. The 70 char per line came from punch cards. Coding style sometimes stifle innovation.

GNU Emacs also has a convention that parameter names be ALLCAPS in the docstring. This limits the possibility of actually having ALLCAPS as parameter name, since emacs is case sensitive, but more so, it adds manual burden to programer. A better way is to introduce markers, similar to emacs `symbol' convention.

check this link out, by the guy who created the Mongrel web server that was used by twitter. (also famous for http://programming-motherfucker.com/ )

〔 Programming Languages Have Social Mores Not Idioms 2012-08-19 By Zed A Shaw. @ http://learncodethehardway.org/blog/AUG_19_2012.html

Instead of naming convention and other misc conventions, what might be a step forward, and is happening today in many languages, is to make it part of the language, enforced either by syntax or by the lang's compiler. For example, predicate function all ends in ?, mutation functions ends in !, or dollar sign sigils means global system var, Caps var name means global var, @ sigil means instance var, etc, all enforced by the lang.

Some convention seems obviously good. But, we need awareness of the many problems. By keep discussing about coding style as we have done so, we dilute the idea of automated and language enforced.

see

corrected a bug from yesterday. Emacs: comment-line vs comment-dwim

Emacs: comment-line vs comment-dwim

Emacs: Cycle Replace Space Hyphen Underscore (more change. Now, by default it works on current line. (it was current word before))

Emacs: Rename File from Space to Hyphen/Underscore (updated code. Now first check if there's space before rename. So you don't get error like file already exist.)

Emacs: Insert Date Time (major rewrite. Now choice of several date time formats.)

Emacs: Tabs, Space, Indentation Setup (updated.)

Emacs: Insert Brackets by Pair (updated code. now, brackets will wrap around symbol when in lisp modes)

Emacs: Reformat Lines for Source Code (bug fix. Now, run of space will be compacted to 1. Refresh page.)

Emacs: Clean Empty Lines (fixed a bug that prevents before save hook from working.)

Emacs: Replace Greek Letter Names to Unicode (new)

Emacs: xah-replace-pairs.el Multi-Pair Find Replace

new version. The functions xah-replace-pairs-region and xah-replace-regexp-pairs-region now have options to let you highlight. That is, the replaced string will be highlighted in buffer.

Emacs: Open Last Closed File. Add that, if you haven't already.

Emacs: Rename File from Space to Hyphen/Underscore (on its own page)

The command posted yesterday also reverted, so they are not dependent. See Emacs: Cycle Replace Space Hyphen Underscore

Emacs: Cycle Replace Space Hyphen Underscore

new feature. When in dired, it automatically rename current or marked files by replacing space to underscore. You can modify it to rename to using hyphen.

emacs: user-error: tags file doesn't exist

“user-error: File /home/y/TAGS does not exist”

3 hours wasted trying to find where is that path set.

Couldn't find it in any elisp file in my init, lib, or “.emacs.d”.

it seems emacs memorized prev value i used long ago.

Solution: (setq tags-table-list '()) once.

Like it? Buy Xah Emacs Tutorial. Thanks.

or, buy something from Best Keyboard for Emacs

Xah Emacs Blog Archive Index