What's New in Emacs 25.1, Ditaa and Artist-mode

Table of Contents

What's new in Emacs 25.1?

There's a lot of stuff coming in Emacs 25.1, which should be out sometime this year!

When-let and If-let, thread-first and thread-last

You may be familiar with when-let and if-let from Clojure, but essentially they allow you to bind and also check the truthy-ness of a variable:

(if-let ((cat-offset (string-match "cats" "there are 23 cats")))
    (format "I found some cats at char %d" cat-offset)
  (format "I couldn't find any cats"))

when-let is the same, with just a single branch

Threading macros

Threading is like Clojure's -> and ->>:

(thread-first
    "foo"
  (concat "bar")
  string-reverse
  (substring 2))

(substring (string-reverse (concat "foo" "bar")) 2)
(thread-last "I wish I had a boat"
  reverse
  (replace-regexp-in-string "taob" "racecar")
  reverse)

The seq.el and map.el libraries for dealing with sequences and maps

seq.el is a library for dealing with sequences instead of just lists, it works on vectors and strings (sequences of characters).

map.el is a library for dealing with maps, finally, elisp is catching up with Clojure.

There is a great tutorial for these here: http://nicolas-petton.fr/ressources/emacsconf2015/index.html

Note that seq.el is on GNU ELPA, but map.el is not on there yet (so it will only be available with Emacs 25.1 or later)

let-alist

If you deal with alists, there's now a nice destructuring function for these.

So if you have an alist like:

(defvar things-and-colors
  '((car . "white")
    (shirt . "blue")
    (backpack . "black")))
things-and-colors

Usually you'd have to do:

(defvar things-and-colors
  '((car . "white")
    (shirt . "blue")
    (backpack . "black")))

(let ((car-color      (cdr (assq 'car things-and-colors)))
      (shirt-color    (cdr (assq 'shirt things-and-colors)))
      (backpack-color (cdr (assq 'backpack things-and-colors))))
  (message "I am wearing a %s shirt and %s backpack and drive a %s car"
           shirt-color backpack-color car-color))

Now you can do:

(defvar things-and-colors
  '((car . "white")
    (shirt . "blue")
    (backpack . "black")))

(let-alist things-and-colors
  (message "I am wearing a %s shirt and %s backpack and drive a %s car"
           .shirt .backpack .car))

EWW changes

Now from within Eww, you can toggle fixed-width versus variable-width fonts. For example:

http://jvns.ca/blog/2016/02/12/why-i-love-log-files/

The actual method is eww-toggle-fonts and is bound to F by default

You can also make a page "readable" by hitting R (eww-readable), for example:

http://arstechnica.com/gadgets/2016/04/ubiquitis-8-port-poe-switch-is-a-solid-complement-for-a-home-unifi-setup/

It should remove a lot of the junk that isn't part of the article

Module System

If you compile Emacs with the --with-modules command, you can use modules, which are extensions written in a compiled language.

Check out some example modules on the Emacs mailing list.

There's also a good introduction on how to write your own modules.

Basically it lets you call into a compiled library (.so, .dll, .dyllib).

Great small example: https://github.com/syohex/emacs-eject

More complex example: https://github.com/syohex/emacs-mruby-test

And it can be used to add features to Emacs that aren't included in core: https://github.com/tromey/emacs-ffi

Embedded XWidgets and browsing urls

There's no image for this, if you compile Emacs with the --with-xwidgets branch, you can now use the xwidget-webkit-browse-url.

Searching for non-ASCII characters

Allows you to search for Unicode characters (like accented characters) with a regular regex incremental search.

(setq search-default-mode 'character-fold-to-regexp)
Key in Isearch What it does
M-s w search for a sequence of words
M-s ' search with character fold to regexp
M-s _ search for a symbol

Then you can search for Résumé (character folding)

Or through a sentence, regardless… of punctuation! (words)

Or for a specific symbol in a programming language. (you can also search for a specific symbol at point with M-s .)

If you want character folding in query-replace (M-%), set replace-character-fold to t.

Configurable text quoting

Good ol' flame war (not quite emacs vs vim level) - regular quotes versus smart quotes. Now you don't have to pick

Basically it's this variable:

text-quoting-style

Which has four different settings:

‘curve’ means quote with curved single quotes ‘like this’.
‘straight’ means quote with straight apostrophes 'like this'.
‘grave’ means quote with grave accent and apostrophe `like this'.
The default value nil acts like ‘curve’ if curved single quotes are
displayable, and like ‘grave’ otherwise.

Comment line

There's a new command bound by C-x C-; by default that invokes comment-line, it comments the line out without having to select a region.

Un-pretty symbols when cursor or point is over them

The pretty symbols are nice, they change the pretty symbol so you can see what it originally was.

If you set prettify-symbols-unprettify-at-point to t, it means anytime the cursor is in it, show the original. You can also set it to right-edge which will show the un-pretty symbol if the cursor is on the right edge of the pretty symbol.

Here's an example:

(setf my-fun (lambda (x) (+ 2 x)))

Enhanced Rectangle editing

Rectangle mode has had a bunch of stuff added. To enter rectangle mark mode, hit C-x SPC.

  • Line one
  • line two
  • three
  • four

Once in it, you can toggle between corners with C-x C-x now.

Additionally, there is now a rectangle "preview" when things are going to be added.

Miscellaneous other things

You can now install packages from a directory by specifying the directory when invoking package-install-file, or running package-install-from-buffer from a dired buffer

If you hit M-p in query-replace-regexp (usually bound to M-%), you can now see both the before and after. (DEMO)

Emacs 25.1 is speedier (at least for me), but that's purely subjective.

Artist mode and Ditaa

Artist mode is a great mode that lets you draw ASCII art with your mouse, this is super handy for generating all those ASCII art diagrams you wanted to make in your code.


It's even more handy when you combine it with Ditaa, which stands for "DIagrams Through Ascii Art". Let's play around with org-mode and ditaa, so we need to ensure it's loaded as a valid language:

(Also make sure you install it with homebrew, or apt, or dnf, or whatever)

(org-babel-do-load-languages
     'org-babel-load-languages
     '((ditaa . t)))

;; This happened to be the directory it gets installed with Fedora
(setq org-ditaa-jar-path "/usr/share/java/ditaa.jar")

Now, let's play!

Boxes

+-------+
|       |
| A box |
+-------+

ditaa-box1.png

You can color boxes by "cNNN" where NNN are RGB codes:

/---------\   +----------+   +---------\
| c243    |   | cRED     |   |         |
|         |   |          |   |         |
|         |   |          |   |         |
\---------/   +----------+   +---------/

ditaa-box2.png

There's also different types of boxes depending on the type

+----------+  +---------+  +--------------+
|{d}       |  |{s}      |  |{io}          |
|          |  |         |  |              |
| Document |  | Storage |  | Input/Output |
|          |  |         |  |              |
+----------+  +---------+  +--------------+

ditaa-box3.png

Lines

In addition to boxes, you can of course draw arrows or lines

+--------+          +---------+
|        |          |         |
|   A    +----------+    B    |
|        |          |         |
+--------+          +----+----+
                         ^
                         |
                         +------+
                                |
          +--------+     /------+
          |        |     |
          |   C    +<----/
          |        |
          |        |
          +--------+

ditaa-lines1.png

You can also add points to lines and boxes:

+--------+          +---------+
|        |          |         |
|        *          |         *
|        |          |         |
+--------+          +---+-----+
     ^                  |
     |                  |
     |                  *
     \------*-----------+

ditaa-lines2.png

And finally, you can make anything dotted by putting either : or = in it, like so:

+----------+            +------------+
| cGRE     |            |            |
|   Box A  +----+-------+            |
|          |    |       |            :
|          |    |       | Thing      |
+----------+    |       +------------+
                |
                |
                |          +----------+
                |          | {s}      |
                |          |          |
                +------=-->| Storage  |
                           |          |
                           |          |
                           +----------+

ditaa-lines3.png

Author: Lee Hinman

Created: 2016-04-20 Wed 08:56

Validate