Irreal: Drag and Drop Into an Org Buffer

John Kitchin has a very nice post in which he presents at bit of Elisp that enables us to drag and drop images into an Org buffer. The code is short and easy to understand. I just cut it out of his post, pasted it into my init.el, and evaluated it. After that I could drag and drop just as in his video demonstration. The only problem I had was with the 【Ctrl】 drag and drop. When dragging from the Finder, 【Ctrl】 clicking on an item brings up a menu. What you have to do is drag it over to the Org buffer and then press control before you release the mouse button.

Kitchin's code was developed on a Mac and according to the comments has some problems with Linux machines. If you experience any trouble, you might want to try abo-abo's drag and drop solution. If you're interested, check out his demonstration video.

I really liked that when he first demonstrated it but, as I recall, there was some indication that it wouldn't work on a Mac so I never tried it. After reading Kitchin's post, I downloaded and tried abo-abo's org-download to see how it compared to Kitchin's solution.

I had a couple of glitches but to be fair I didn't do more than a cursory trial. I could have probably resolved my problems with a bit of code reading. On the other hand, abo-abo's solution allows you to grab images from Web pages while Kitchin's code works only with images in the file system. Between the two solutions, you should find one that works for you and meets your needs.

-1:-- Drag and Drop Into an Org Buffer (Post jcs)--L0--C0--July 31, 2015 11:39 AM

Pragmatic Emacs: Cut or copy current line with easy-kill

I’ve previously written about how to cut the current line without selecting it, using some custom lisp code. I’ve since noticed that my recommended setup, prelude already deals with this in a nicer way by using the package easy-kill. If you don’t use prelude, then install easy-kill and add

(global-set-key [remap kill-ring-save] 'easy-kill)

to your emacs config file.

Once you have done this, then C-w with no region selected will cut (kill) the current line, and M-w with no region selected will copy the current line. This is one of those neat shortcuts I use all the time and miss whenever I have to edit text outside of emacs!

The easy-kill package also offers the easy-mark function, that expands highlighted regions by word, line or other useful units, but I prefer expand-region for this purpose.

-1:-- Cut or copy current line with easy-kill (Post Ben Maughan)--L0--C0--July 30, 2015 10:02 PM

Irreal: Embedding Youtube Videos in Org Files

Artur Malabarba has a nice post on embedding Youtube videos in Org files. I do that occasionally for blog posts by using the HTML embedding code that Youtube supplies with each video. It turns out, though, that you can do it directly from Emacs by defining a new Org link type.

This has the advantage that you can follow the link directly from the Org file or even export it to, say, PDF via LaTeX. It's really easy to set up and once you do it would be easy to completely automate the link insertion the way I do for normal Web pages.

Malabarba has a separate post on how to add Org links that you might also find useful. If you frequently embed Youtube links in your blog posts and you blog from Emacs with Org mode, you should definitely take a look at Malabarba's posts. They're sure to pay dividends.

-1:-- Embedding Youtube Videos in Org Files (Post jcs)--L0--C0--July 30, 2015 01:41 PM

Endless Parentheses: Embedding Youtube videos with org-mode links

If you’re a frequent reader, no doubt you noticed an embedded Youtube video on a post a couple of weeks ago. Youtube makes it pretty simple to embed videos, they give you the entire iframe HTML code to use, but this wouldn’t really be Emacs if we couldn’t make things just a little bit easier. Just add the snippet below to your init file, and you’re good to go.

(defvar yt-iframe-format
  ;; You may want to change your width and height.
  (concat "<iframe width=\"440\""
          " height=\"335\""
          " src=\"\""
          " frameborder=\"0\""
          " allowfullscreen>%s</iframe>"))

 (lambda (handle)
    (concat ""
 (lambda (path desc backend)
   (cl-case backend
     (html (format yt-iframe-format
                   path (or desc "")))
     (latex (format "\href{%s}{%s}"
                    path (or desc "video"))))))

To use this, just write your org links in the following way (optionally adding a description).


When you export to HTML, this will produce that same inlined snippet that Youtube specifies. The advantage (over simply writing out the iframe) is that this link can be clicked in org-mode, and can be exported to other formats as well.

Comment on this.

-1:-- Embedding Youtube videos with org-mode links (Post)--L0--C0--July 28, 2015 12:00 AM

Pragmatic Emacs: Basic spell checking

Use M-x ispell-buffer to run spell-check on the whole buffer, or M-$ to check the spelling of the word at the cursor position. The spell check will suggest corrections for the words, or let you save the word to your personal dictionary (by hitting i).

Emacs can use several back-ends to do the actual spell checking, and there is a good comparison of them here. For myself, I have found hunspell to give the best suggested corrections. I installed hunspell with macports

sudo port install hunspell

and then added the following to my emacs config file:

;; spelling                                                               ;;
;; use hunspell
(setq-default ispell-program-name "hunspell")
(setq ispell-really-hunspell t)
;; tell ispell that apostrophes are part of words
;; and select Bristish dictionary
(setq ispell-local-dictionary-alist
      `((nil "[[:alpha:]]" "[^[:alpha:]]" "[']" t ("-d" "en_GB") nil utf-8)))
-1:-- Basic spell checking (Post Ben Maughan)--L0--C0--July 27, 2015 08:50 PM

(or emacs: Using Recoll desktop search database with Emacs

I know that most Emacs hackers love the simplicity and usability of grep, but sometimes it just doesn't cut it. A specific use case is my Org-mode directory, which includes a lot of org files and PDF files. There are just too many files for grep to be efficient, plus the structure of PDF doesn't lend itself to grep, so another tool is required: a desktop database.

I got into the topic by reading John Kitchin's post on swish-e, however, I just couldn't get that software to work. But as a reply to his post, another tool - recoll was mentioned on Org-mode's mailing list. In this post, I'll give step-by-step instructions to make Recoll work with Emacs.

Building Recoll

I'm assuming that you're on a GNU/Linux system, since it's my impression is that it's the easiest system for building (as in make ...) software. Also, it's the only system that I've got, so it would be hard for me to explain other systems.

If you want to toy around with the graphical back end of Recoll, you can install it with:

sudo apt-get install recoll

Unfortunately, the shell tool recollq isn't bundled with that package, so we need to download the sources. The current version is 1.20.6.

Extract the archive

After downloading the archive, I open ~/Downloads in dired and press & (dired-do-async-shell-command). It guesses from the tar.gz extension that the command should be tar zxvf. By pressing RET, I have the archive extracted to the current directory. I've actually allocated ~/Software/ for installing stuff from tarballs, since I don't want to put too much stuff in ~/Downloads.

Open ansi-term

I navigate to the recoll-1.20.6/ directory using dired, then press ` to open an *ansi-term* buffer for the current directory.

Here's the setup for that (part of my full config):

(defun ora-terminal ()
  "Switch to terminal. Launch if nonexistent."
  (if (get-buffer "*ansi-term*")
      (switch-to-buffer "*ansi-term*")
    (ansi-term "/bin/bash"))
    (get-buffer-process "*ansi-term*"))

(defun ora-dired-open-term ()
  "Open an `ansi-term' that corresponds to current directory."
  (let ((current-dir (dired-current-directory)))
     (if (file-remote-p current-dir)
         (let ((v (tramp-dissect-file-name current-dir t)))
           (format "ssh %s@%s\n"
                   (aref v 1) (aref v 2)))
       (format "cd '%s'\n" current-dir)))
    (setq default-directory current-dir)))

(define-key dired-mode-map (kbd "`") 'ora-dired-open-term)

Configure and make

Here's a typical sequence of shell commands.

./configure && make
sudo make install
cd query && make
which recoll
sudo cp recollq /usr/local/bin/

I was a total Linux newbie 5 years ago and had no idea about shell commands. Using only the first two lines, you can build and install a huge amount of software, so these are a great place to start if you want to learn these tools. I actually got by using only those two lines for a year a so.

After the first run or ./configure it turned out that I was missing one library, so I had to do this one and redo the ./configure step.

sudo apt-get install libqt5webkit5-dev

I think this one would work as well:

sudo apt-get build-dep recoll

Configuring Recoll

I only launched the graphical interface to select the indexing directory. It's the home directory by default, I didn't want that so I chose ~/Dropbox/org/ instead. Apparently, there's a way to make the indexing automatic via a cron job; you can even configure it via the graphical interface: it's all good.

Using Recoll from Emacs

Emacs has great options for processing output from a shell command. So first I had to figure out how the shell command should look like. This should be good enough to produce a list of indexed files that contain the word "Haskell":

recollq -b 'haskell'

And there's how to adapt that command to the asynchronous ivy-read interface:

(defun counsel-recoll-function (string &rest _unused)
  "Issue recallq for STRING."
  (if (< (length string) 3)
      (counsel-more-chars 3)
     (format "recollq -b '%s'" string))

(defun counsel-recoll (&optional initial-input)
  "Search for a string in the recoll database.
You'll be given a list of files that match.
Selecting a file will launch `swiper' for that file.
INITIAL-INPUT can be given as the initial minibuffer input."
  (ivy-read "recoll: " 'counsel-recoll-function
            :initial-input initial-input
            :dynamic-collection t
            :history 'counsel-git-grep-history
            :action (lambda (x)
                      (when (string-match "file://\\(.*\\)\\'" x)
                        (let ((file-name (match-string 1 x)))
                          (find-file file-name)
                          (unless (string-match "pdf$" x)
                            (swiper ivy-text)))))))

The code here is pretty simple:

  • I don't start a search until at least 3 chars are entered, in order to not get too many results.
  • I mention :dynamic-collection t which means that recollq should be called after each new letter entered.
  • In :action, I specify to open the selected file and start a swiper with the current input in that file.


I hope you found this info useful. It's certainly pretty cool:

cd ~/Dropbox/org && du -hs
# 567M .

So there's half of a gigabyte of stuff, all of it indexed, and I'm getting a file list update after each new key press in Emacs.

If you know of a better tool than recoll (I'm not too happy that match context that it gives via the -A command option), please do share. Also, I've just learned that there's helm-recoll out there, so you can use that if you like Helm.

-1:-- Using Recoll desktop search database with Emacs (Post)--L0--C0--July 26, 2015 10:00 PM

Alex Schroeder: Gmail, Gnus and GPG

I wrote some instructions for setting up Gmail, Gnus and GPG. I used Emacs 24.5 and GPG 2.0 for this tutorial.

If you’re on a Mac

I tried this using my Mac and a Guest account. A Guest account has all its files deleted when you log out. It’s as “clean” as I could get.

You can install Emacs in various ways. You could use Emacs For Mac OS X. “Pure Emacs! No Extras! No Nonsense!” This is what I used to run. I’ve also built Emacs from source many times. Just remember to ./configure --with-ns before you start. You can install it from Homebrew: You could brew install emacs or you could install Yamamoto Mitsuharu’s Emacs Mac Port. This last variant is what I’m using right now.

brew tap railwaycat/emacsmacport
brew install emacs-mac --with-gnutls --with-imagemagick --with-official-icon --with-xml2
brew linkapps emacs-mac

As for GPG, you have two options. You can install GPG via GPG Suite. This is what I used at first. gpg --version said gpg (GnuPG/MacGPG2) 2.0.27 (the current, stable version is 2.0.28). But I wanted to install GPG via Homebrew. If you want to try it as well, make sure you uninstall the GPG Suite if you had it installed.

If you just install gpg2, you won’t be able to enter your passphrase from within Emacs with a GUI. You’ll see a simple, cut off message saying epa-file--find-file-not-found-function: Opening input file: Decryption failed,. If you only use Emacs within terminal windows, no problem. No need to do anything. But if you like to use Emacs with fonts and colors, menus and scrollbars, then you need to install a special variant of pinentry in order to get a separate Pinentry window:

brew install gpg2
brew install pinentry-mac

Once you have done that, change your ~/.gnupg/gpg-agent.conf file so that it has only this one line:

pinentry-program /usr/local/bin/pinentry-mac

When you install gpg2, it tells you to put use-standard-socket in your ~/.gnupg/gpg-agent.conf file. Don’t do that unless you only want to use Emacs from a terminal. Here’s a sample session in a terminal, showing you what you’ll get, if you don’t use pinentry-mac:

alex@Megabombus:~$ echo "This is a test." > test
alex@Megabombus:~$ gpg --recipient kensanata --encrypt test
alex@Megabombus:~$ ls test*
test     test.gpg
alex@Megabombus:~$ gpg --output test2 test.gpg 

You need a passphrase to unlock the secret key for
user: "Alex Schroeder <>"
8192-bit RSA key, ID 4529A45C, created 2015-03-01 (main key ID ACECFEAE)

gpg: encrypted with 8192-bit RSA key, ID 4529A45C, created 2015-03-01
      "Alex Schroeder <>"
alex@Megabombus:~$ ls test*
test     test.gpg test2
alex@Megabombus:~$ diff test test2

When asked for your passphrase, you’ll see something like the following:

               │ Please enter the passphrase to unlock the secret key for the OpenPGP certificate:  │
               │ "Alex Schroeder <>"                                            │
               │ 8192-bit RSA key, ID 4529A45C,                                                     │
               │ created 2015-03-01 (main key ID ACECFEAE).                                         │
               │                                                                                    │
               │                                                                                    │
               │ Passphrase *****************************************************************______ │
               │                                                                                    │
               │            <OK>                                                  <Cancel>          │

This pinentry works in a terminal, but it won’t show up when GPG is called by GUI Emacs! Install pinentry-mac and you’ll be able to provide your passphrase when using Emacs.

If you already tinkered with gpg before changing ~/.gnupg/gpg-agent.conf, you’ll have to reload gpg-agent.

alex@Megabombus:~$ echo RELOADAGENT | gpg-connect-agent


-1:-- Gmail, Gnus and GPG (Post)--L0--C0--July 24, 2015 06:09 PM

(or emacs: New Ivy multi-action exit

So many Emacs commands and bindings, but little time to learn them all. That's why many-in-one solutions like hydra are often a good deal: you only remember the base binding, and get more info along the way if you get lost.

I've wanted to optimize this approach when it comes to completion as well. In last month's post I described how you can get help / jump to definition / jump to info for the current F1 v (counsel-describe-variable) candidate with C-m / C-. / C-,. While that approach can be viable, it has a few problems. The first problem is that it's not discoverable: you may be using C-m option for ages and not know that C-. and C-, exist. The second problem is that it's not extensible: if you wanted more actions, there are hardly any good bindings left in the minibuffer to bind those actions.

In a more recent post, I described a solution that alleviates both problems. When you press C-o, you see how many actions are available, and you can cycle them with w and s. However, while discoverable, this approach is cumbersome if you already know what you want to do. Especially cycling can't be great when there are a lot of actions.

So today I've added a new approach in addition to the previous one. When you press M-o (ivy-dispatching-done), you get a hint showing you which actions are available. It's like C-m (ivy-done), only allows you to quickly select the action. Conveniently, the default action is bound to o, so M-o o is equivalent to C-m.

Here's how I add one more action to the default one of ivy-switch-buffer:

    (lambda (x)
      (kill-buffer x)
      (ivy--reset-state ivy-last))

So now:

  • M-o o will still switch to selected buffer.
  • M-o k will kill the selected buffer.

If you're familiar with hydra, the format is the same: (key cmd hint). This approach is very extensible: you can add actions and bindings to commands without changing the code of the original command. It's really fast: you're typing just one extra key to select an action. And you'll hardly run out of keys to bind, with 25 lower case keys at your disposal (other bindings work as well, I just think that lower case keys are the fastest to press).

In case you wonder what (ivy--reset-state ivy-last) does, it's used to update the list of buffers, since one of them was deleted. This way, you can delete e.g. 4 buffers with C-x b C-o s gggg, and have the buffer list update after each g.

New functionality in action

Let's look at one package that has a multitude of actions available for each candidate - projectile:

(defvar helm-projectile-projects-map
  (let ((map (make-sparse-keymap)))
    (set-keymap-parent map helm-map)
    (helm-projectile-define-key map
        (kbd "C-d") #'dired
        (kbd "M-g") #'helm-projectile-vc
        (kbd "M-e") #'helm-projectile-switch-to-eshell
        (kbd "C-s") #'helm-find-files-grep
        (kbd "M-c") #'helm-projectile-compile-project
        (kbd "M-t") #'helm-projectile-test-project
        (kbd "M-r") #'helm-projectile-run-project
        (kbd "M-D") #'helm-projectile-remove-known-project)
  "Mapping for known projectile projects.")

Here's the basic Ivy function for selecting a project:

(defun ivy-switch-project ()
   "Switch to project: "
   (if (projectile-project-p)
       (cons (abbreviate-file-name (projectile-project-root))
   :action #'projectile-switch-project-by-name))
(global-set-key (kbd "C-c m") 'ivy-switch-project)

And now let's add all those actions:

 '(("d" dired "Open Dired in project's directory")
   ("v" helm-projectile-vc "Open project root in vc-dir or magit")
   ("e" helm-projectile-switch-to-eshell "Switch to Eshell")
    (lambda (x)
      (helm-do-grep-1 (list x)))
    "Grep in projects")
   ("c" helm-projectile-compile-project "Compile project")
   ("r" helm-projectile-remove-known-project "Remove project(s)")))

Here's what I get now after pressing M-o:


Looks pretty good, I think. I hope you find the new approach useful. The multi-action exit is currently enabled by default for ivy-switch-buffer, counsel-locate and counsel-rhythmbox, but you can add actions yourself to almost any command that uses ivy-read. In the rare case when ivy-read isn't in the tail position, you can use ivy-quit-and-run inside the added action functions.

-1:-- New Ivy multi-action exit (Post)--L0--C0--July 22, 2015 10:00 PM

Endless Parentheses: Fixing DOuble CApitals as you type

This is something that’s bothered me for a very long time. My pinky is slow when it comes to releasing the Shift key, and frequently leads to typos. MOst typos (hitting letters in the wrong order) are already covered by auto-correction, but there’s another common typo that it doesn’t fix. EVery now and then, I’ll start a sentence with two uppercase letters.

After the billionth time that it happened to me, I finally took the time to write up a question on Emacs.StackExchange. The answers were fast, and so high quality that I don’t even have improvements to suggest. Instead, I’ll just point you straight to Dan's answer, and show how I activate it.

(add-hook 'text-mode-hook #'dubcaps-mode)

Comment on this.

-1:-- Fixing DOuble CApitals as you type (Post)--L0--C0--July 20, 2015 12:00 AM

Emacs Redux: ace-jump-mode is Dead, Long Live Avy

People often ask how am I navigating efficiently Emacs windows and buffers. I have the feeling they expect me to share with them some secrets that would turbo-charge common commands like C-s, M-f, C-x o, etc. I don’t, however, use those commands that much. Ever since I saw that vim’s EasyMotion has been ported to Emacs, I’ve been using that port - namely ace-jump-mode.

Basically, it allows you to navigate to every visible portion of your Emacs (buffers & windows) with only a handful of keystrokes (usually one two activate it and one or two to get where you want to go). You can see it in action in this excellent video. ace-jump served me well for years, but I’ve had a few gripes with it that were never addressed (multi-char targets, CamelCase support, etc). I would have implemented those myself, if the project was maintained at all, but alas - that’s not the case. Seems I wasn’t the only one who was frustrated with ace-jump, as the prolific Oleh Krehel reimplemented it pretty much from scratch for the purposes of his excellent ace-window library. Once I got wind of this, I managed to persuade Oleh to start distributing his rewrite as a standalone project, which he dubbed avy.

Avy features everything ace-jump does and more. Apart from the many extra features, its codebase is way cleaner and readable and Oleh is a fantastic and very responsive maintainer. So, as far as I’m concerned ace-jump is now a dead project and pretty much everyone who’s using it should try out avy instead. Their usage and interface are pretty similar, so the learning curve is non-existing. By the way, here’s avy in action:

And what about my usage of avy? Nothing fancy here - I just bind the commands I consider most important to handy keystrokes.

(global-set-key (kbd "C-c j") 'avy-goto-word-or-subword-1)
(global-set-key (kbd "s-.") 'avy-goto-word-or-subword-1)
(global-set-key (kbd "s-w") 'ace-window)

avy-goto-word-or-subword-1 is aware of CamelCase words and I do a lot of programming in languages that use those extensively.

avy has one more thing going for it - it’s part of the default Emacs package repo GNU ELPA, which means that you can install it right away without having to setup any third-party repositories (which you’ll probably need sooner or later).

avy and ace-window are naturally part of Prelude.

P.S. Oleh, one of those days you should rename ace-window to avy-window. :-)

-1:-- ace-jump-mode is Dead, Long Live Avy (Post)--L0--C0--July 19, 2015 08:48 AM

Emacs Redux: JDEE Reborn

JDEE (Java Development Environment for Emacs) used to be best way to develop Java apps in Emacs a while back. It offered a ton of cool features, like smart auto-completion and a debugger. Unfortunately at some point the development slowed down significantly and the project went in a catatonic state. There was pretty much no activity for years in the official SourceForge repo and there was also no support for features introduced in Java 5+.

Recently, however, the project migrated to GitHub and it’s now way easier to get involved. Seems that some people have already started work on updating JDEE to support modern JDKs and modern Emacs functionality.

That’s a really exciting project, as Java support has traditionally been a weakness of Emacs and I’m writing this post with the hope that more people will help make JDEE great again.

So what are you waiting for? If you’re into Java and friends (Scala, Clojure, Groovy, etc), check out the new official repo and let’s get this party started!

-1:-- JDEE Reborn (Post)--L0--C0--July 19, 2015 08:37 AM

Mathias Dahl: Evaluating elisp expressions from a web page with a custom URI scheme


Very boring title, eh? :) Well, this is kinda neat...

Some of you might already know that you can install a custom URI scheme handler in most operating system. Today I did an experiment with that together with Emacs and it turned out quite nicely. I did
this in Windows but it should work in GNU/Linux and OS X as well.

So, what is an URI scheme?

Briefly explained, the URI scheme is the "http" part in URLs that we all use everyday. Other examples are "ftp" and "file". The most common ones are handled by your web browser but you can also have another program on your computer handle a certain URI scheme. You can register your own URI schemes as well and in this post we will experiment with a new URI scheme that we name "emacs", for evaluating expressions/executing commands in Emacs.

A warning

If you decide to do this, you should be very careful, since it could be a big security risk. Either you let the warning from your web browser always be there to warn you (it can be supressed easily, for a
better user experience) or you register a secret URI scheme (like "myverysecretemacsurischeme") that no one else knows about. Otherwise, bad people can do very nasty things with your computer...

Okay, with that aside, let's go!

Step 1 - Registering a new URI scheme

In Windows you register a new URI scheme in the Windows registry (where else...). Basically you have to create the following key/folder structure under the HKEY_CLASSES_ROOT hive:

<name of URI scheme handler>

Lastly, the "command" key's Default value (right hand side) should have the path to the program handling the request, and %1 should be there to, to send in the parameters from the URL to the program.

If you dare, you can save the following snippet of text as something.reg on your PC, and double click that file. It will add an URI scheme handler for the "emacs" scheme for you. You have to change the path to the program afterwards:

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\emacs]"URL Protocol"=""
[HKEY_CLASSES_ROOT\emacs\shell\open\command]@="f:\\Dropbox\\home\\dat\\doc\\src\\bat\\emacsschemehandler.cmd \"%1\""

Step 2 - A script to handle the new URI scheme

To handle the new URI scheme I created a small cmd file that processes the arguments a bit and then starts emacsclient. It looks like this:

REM f:\Dropbox\home\dat\doc\src\bat\emacsschemehandler.cmd

@echo off

REM Pick up all arguments to the script (in case there are spaces)
set emacscommand=%*

REM Stript away the part we don't need...
set emacscommand=%emacscommand:emacs:=%

REM Start emacsclient
f:\Dropbox\home\pgm\emacs-24.3\bin\emacsclient -n -e %emacscommand%

Save the script above as a .cmd file on your computer and update the registry to reflect the path to the .cmd file on your system. Also update the path to where your emacsclient is.

The script is, as can be seen, very simple and basically it just trims off part of the argument from the web browser that we do not need and use the rest as an argument to emacsclient. If you decide to use
another name than "emacs" for your own experiments, make sure to update "emacs:" above to whatever name you picked (plus a colon).

Step 3 - Testing it from a web page

Now you only need a web page with some links to try it out. I have provided a couple of links below that you can try right now, if you decided to use the "emacs" URI scheme, that is. The code for the links looks like this (if you do not trust me, view the source code for this blog post):
<a href='emacs:(message """Hello, Emacs!""")'>Hello, Emacs!</a> <a href="emacs:(calendar)">Open Calendar</a><a href="emacs:(info-emacs-manual)">Open the Emacs manual</a>
Here are the links:

Hello, Emacs!
Open Calendar
Open the Emacs manual

The triple double quotes in the first example are needed in order to send strings from the cmd file to emacsclient. That is why I used single quotes around the href value, which I normally don't like.

Now, what do you wait for, try it! Go go go! :)

So, what can this be used for?

Well, not sure. For me it was mostly a nice experiment, but I can see some uses for people who work a lot in Emacs but also a lot in a web browser and where they need some kind of interaction between
those. Perhaps something nice can be done together with Org mode and documentation of code, where you view the documentation in a browser but let the user try out code in Emacs, or just jump to a particular section in the Org mode document there. I guess the possibilities are endless, as with most things Emacs... :)

Hope you enjoyed it!


-1:-- Evaluating elisp expressions from a web page with a custom URI scheme (Post Mathias Dahl ( 18, 2015 04:12 PM

Grant Rettke: Vintage Computer Programming Book Market About To Explode!

Last week I was day-dreaming about Forth and vintage computers again. Same old day-dreams. The TI-99/4A with TurboForth seems like the perfect place to start learning about both. TurboForth has lots of features and it runs in emulators and “on the metal”. Cool.

The best way to learn Forth is interactively. How do you do it with Org Mode, though? Can we have the same features you would expect with any other programming language even though it is running inside of an emulator? There must be an easy way to run at the command line, redirect input and output, or maybe telnet into the machine.

V9t9 is a Java-based and open-sourced emulator there on GitHub. If it doesn’t have telnet into it, then it can be added. That got me thinking (daydreaming?) again about the fun of simple computers. Whatever approach you use to access them, using Org seems like a great way to write new books about them.

They are simpler. They are a great place to start. There is tons of great literature out there already. Now add Emacs and Org-Mode to the mix to practice Literate Programming.

It seems like there is a huge opportunity for great new books about old computers and programming languages. Export to LaTeX and publish, and there you go. Very fun and very cool.

-1:-- Vintage Computer Programming Book Market About To Explode! (Post Grant)--L0--C0--July 18, 2015 02:33 AM

Ryan Rix: My Inventory

Over on Hardcore Freestyle Emacs I am beginning to expand my documentation of my Inventory system, which I am using to catalog the things that I own -- physical objects, mainly but also my eBooks and valuable digital artifacts. It is a system in its infancy, but provides a good example of how nicely the pieces of Emacs infrastructure I'm using are put together -- namely how simple it is to integrate Helm, Org-mode and Org-links together to create something inherently useful
-1:-- My Inventory (Post)--L0--C0--July 18, 2015 12:00 AM

sachachua: July 2015 Emacs Hangout

We talked about Python, Org Mode, system administration, keybindings, Hydra, and other neat things. =)

I’ll probably set up another hangout mid-August, or we’ll just do the one on the 29th. We’ll see! You can follow the Emacs Conferences and Hangouts page for more information, or sign up to get e-mails for upcoming hangouts. Past Emacs Hangouts

Text chat (links edited to avoid weird wrapping things):

me 9:18 PM literate devops link
Daniel Gopar 9:34 PM config link
me 9:37 PM jwiegley/dot-emacs jwiegley – haskell
Howard Melman 9:48 PM cocoa-text-system
Mr Swathepocalypse 9:55 PM I have to go attend to some work stuff, I look forward to watching the rest of the hangout later on.
me 9:55 PM Orgstruct
Mr Swathepocalypse 9:55 PM Thanks guys!
me 9:55 PM Bye Dylan! my config erc erc-pass
Howard Abrams 9:59 PM Did I mention how I’ve been using emacs mail to mime encode an org-mode buffer into HTML for the most awesome mail messages.
Daniel Gopar 10:05 PM Have you guys used “helm-M-x”? It’s part of the helm package I believe
Kaushal Modi 10:07 PM ready to share which-key package
Daniel Gopar 10:10 PM Got to go. Nice talking to everyone.
Kaushal Modi 10:14 PM config link
Kaushal Modi 10:37 PM (setq debug-on-message “Making tags”)
me 10:39 PM org-map-entries
Correl Roush 10:47 PM git graphs
me 10:54 PM imagex-global-sticky-mode imagex-auto-adjust-mode
Kaushal Modi 10:54 PM Emacs-imagex config link example of setting ditaa and plantuml
Correl Roush 10:58 PM writing specs link that has some setup steps listed out as well

The post July 2015 Emacs Hangout appeared first on sacha chua :: living an awesome life.

-1:-- July 2015 Emacs Hangout (Post Sacha Chua)--L0--C0--July 16, 2015 03:16 AM

Grant Rettke: Handling 4 Kinds of Return in Org Mode

You might want more than a few ways to “return” when inside of Org; I did.

Make it really easy to work in existing list items,
headings, and tables

  • This is listed first because I often go back to modify entries
  • <return> because it is used the most
Make it really easy to add new list items, headings, and
table contents

  • M-<return> because the binding comes with Org
For when I want to break out of the default
Org indentation to start working at the beginning of the line for example when
I’m done working in a list or have just created a new heading

  • C-M-<return> because it is next step “lower” in the binding
When I want to insert a new line between the current
and next line then position the cursor correctly indented at the start of it.

  • s-<return> because it is that is the last place in the modifier key chain
-1:-- Handling 4 Kinds of Return in Org Mode (Post Grant)--L0--C0--July 13, 2015 09:24 PM

Eric James Michael Ritz: Emacs: Formatting Integer Ranges With Tiny

Today I want to introduce you to Tiny, yet another Emacs package by the prolific author abo-abo. His most well-known works—such as Hydra, avy, Lispy—allow you to accomplish a lot with a minimal amount of input. Tiny is no different, as it lets you quickly create and manipulate ranges of numbers. In this short post I’ll show you how Tiny works and why I consider it useful.


After installing Tiny all you need to do is bind tiny-expand to a key. This is my personal setup, using John Wiegley’s terrific use-package:

(use-package tiny
  (global-set-key (kbd "C-s-t") 'tiny-expand))

Or you can call (tiny-setup-default) which binds the command to C-;, and off the top of my head I can’t think of another mode which conflicts over binding that key.

Either way, once you have tiny-expand bound to a key you’re ready to go.

Making a Numbered List

Here’s a very simple but practical example: let’s say I want to make a numbered list of five items. With Tiny I can type m1\n5 and then, with the point at the end, I can press the key to which I’ve bound tiny-expand and I’ll end up with this:


The syntax may look cryptic at first, but is quite simple.

m[range start][separator(s)][range end]

So we can breakdown my example of m1\n5 like so:

  1. The initial m is mandatory.

  2. Next is the initial value of the range, in this case one. But this is optional and will default to zero.

  3. Then comes any separator characters to insert between each number. I use \n to add a newline after each number.

  4. And finally is the final value for the range, five in this example.

Fancier Formatting

Do you know how I generated that numbered list of four elements? I used m1\n\n4|%d., which Tiny expands into:





This demonstrates that you can have multiple separator characters; here I use two \n’s for the extra space. But there is that |%d. at the end. Tiny lets you use Emacs Lisp format strings, which you write at the end of your expression and delimit with a vertical bar. The formatting string %d. prints each number as a digit (%d) with a period after it. Used in conjunction with the newline separators it gives me exactly the output I want for a numbered list in Markdown.

Getting Even Fancier

Immediately following the end-range value we can write abbreviated Lisp. The current value is bound to x, so for example m1, 10*xx will expand to 1, 4, 9, 16, 25, 36, 49, 64, 81, 100. That is, the markup loops from one to ten, and at every step executes the Lisp expression (* x x) where x is each number in the range.

Format strings can follow any Lisp expressions, and those strings can themselves contain Lisp expressions wrapped in %(…). Here we see Tiny at its most complete syntax. One way I’ve found this functionality useful is for easily generating numeric data in code, using a combination of Lisp to calculate values and format strings to create the desired output. For example, consider this:

local e = {
m1,\n10|    [%d] = %(exp x)

When I run tiny-expand on the markup inside the braces I end up with this:

local e = {
    [1] = 2.718281828459045,
    [2] = 7.38905609893065,
    [3] = 20.085536923187668,
    [4] = 54.598150033144236,
    [5] = 148.4131591025766,
    [6] = 403.4287934927351,
    [7] = 1096.6331584284585,
    [8] = 2980.9579870417283,
    [9] = 8103.083927575384,
    [10] = 22026.465794806718

Nifty, right?


I hope this shows how useful Tiny can be for rapidly working with ranges of integers. Since you can use any amount of Lisp for crunching numbers and formatting output you can do more with Tiny than create lists of numbers. For example, the source code for Tiny has examples of generating sequences of letters, URLs, shell commands, and more. So I recommend you check it out to stir your imagination, as the examples in the code are written in such a way that you can execute them in place to get an even better idea of how the package works.

If you want to create some output based on a range of integers then it’s hard to beat the efficient expressiveness of Tiny.

(Update: 9th of July 2015) Check out this useful cheat-sheet of Tiny’s syntax submitted by Kaushal Modi

-1:-- Emacs: Formatting Integer Ranges With Tiny (Post ericjmritz)--L0--C0--July 08, 2015 10:13 AM

Ryan Rix: How I Created Hardcore Freestyle Emacs

I've been asked more and more lately how I've gone about creating Hardcore Freestyle Emacs, my literate computing configuration. After all, it's over 100 pages printed, covers damn near everything I use computers for, from chat to email to un-fucking servers to how I remember all of the useless crap that my coworkers love me for knowing. The code itself is mostly the work of others, with my own customizations and improvements and increasingly my own custom ELisp, but the way they fit together is uniquely me.
-1:-- How I Created Hardcore Freestyle Emacs (Post)--L0--C0--July 02, 2015 12:00 AM

sachachua: Emacs Hangout June 2015

Times may be off by a little bit, sorry!

Boo, I accidentally browsed in the Hangouts window before copying the text chat, so no copy of the text chat this time… =|

The post Emacs Hangout June 2015 appeared first on sacha chua :: living an awesome life.

-1:-- Emacs Hangout June 2015 (Post Sacha Chua)--L0--C0--June 30, 2015 07:50 PM

Alex Schroeder: Emacs Live

I’ve been trying to switch from my own Emacs setup to Emacs Live. Some things are great. Some things… I don’t know. They need a lot of getting used to.

I’ve created my own pack in ~/elisp/alex-pack.

In ~/.emacs-live.el:

(live-add-packs '(~/elisp/alex-pack))

Paredit is messing with how I navigate using Control + Arrow Keys.

In my own pack, ~/elisp/alex-pack/init.el:

(dolist (x '(scheme emacs-lisp lisp clojure))
  (let ((hook (intern (concat (symbol-name x) "-mode-hook"))))
    (set hook (delq 'enable-paredit-mode (symbol-value hook)))))

Delete Trailing Whitespace Mode deleted some non-breaking spaces in my SVG document. This may be an indication that I should write better SVG.

In my own pack, ~/elisp/alex-pack/init.el:

(setq before-save-hook
      (delq 'live-clenup-whitespace before-save-hook))

Changing how C-h works. Help is now on M-h. I’ll adapt. Except I’ve found modes where M-h does describe-mode and that confuses me. I think I’m going to stop using the bindings pack provided by Emacs Live.

In ~/.emacs-live.el:

(setq live-packs (delete "stable/bindings-pack" live-packs))

Ispell no longer shows any content in the *Choices* buffer/window. What’s up?

I have trouble accessing the file open history using <up> or M-p. Similarly, I can’t edit the filename using <left> or <right>. What’s up? I think I’m going to disable Ido mode for find-file.

In my own pack, ~/elisp/alex-pack/init.el:

(ido-mode 'buffers)

I like the some of the fontification, but it turns out that I’m starting to confuse the Emacs frame with terminal windows. So I think I’m going to stop using the colour pack provided by Emacs Live.

In ~/.emacs-live.el:

(setq live-packs (delete "stable/colour-pack" live-packs))

Tags: RSS

-1:-- Emacs Live (Post)--L0--C0--June 24, 2015 04:15 PM

Got Emacs?: EmacsConf 2015 (Announcement)

This should be interesting in that there's enough buzz for a Emacs conference.  And they're looking for speakers. This is in San Franscisco, CA.
-1:-- EmacsConf 2015 (Announcement) (Post sivaram ( 23, 2015 05:59 AM

Rubén Berenguel: Using QGIS to create a custom map

I’ve always loved maps. I guess it goes well with liking drawing and maths, there’s a very deep connection (the pun is intended) between the subjects. As a map lover, when we decided to relocate to a somewhat more countryside town, I wanted better-looking maps to wander around the area. I checked government-issued maps, but they were either too large (scale 1:25000) or didn’t show the area I was interested (for the 1:10000 maps.) Thus I did what any other nerd would do: roll my own map as I wanted it.

The end result looks like this (downscaled to 20%)

The real map is 1.4 × 1.2 metres

Getting the data

My first idea was to follow the steps of Dominik Schwarz in his quest for printing a huge map of the world, and harvest images from Google Maps and get away with it. But one of the fundamental parts of my map was supposed to be having all walking routes visible and available. Google Maps won’t show that, or at least not everything. Specially among vines or forests. What’s the point of living close to the Pantà de Foix (the Foix Dam) and not being able to walk there?

Castellet, just beside Pantà de Foix
Hence, I turned to our trusty government, and in particular to the Catalan Cartographic and Geologic Institute (from now on the ICC, which is the Catalan acronym.) They have a powerful online map application, with good quality satellite imagery, elevation data, toponymy… All is available online. And for free download! You only need to register, and seem to be limited to one download at a time. No big issue, although I needed to get 16 satellite tiles.

There is a huge amount of data available for download. Since my knowledge of technical map stuff ended at knowing that the technical term for what I wanted to do is GIS , I wasn’t really sure what files I needed and what I could do with them on a Mac without having to pay for a dedicated app.

The first step was finding a free app that could “do maps.” After some Googling it was pretty clear it had to be QGIS (formerly known as Quantum GIS) which is free, open-source and available cross-platform. It was quite straightforward to install on Mac, just needing some extra libraries to work with the satellite image files I was using. Once I had it, the real “nightmare” started, where I had to decide what kind of files I needed and what they were good for. This is where ICC helped, since they have documentation for all their file types, not only explaining what they have but also what they are useful for.

For a starter I downloaded all satellite imagery with a scale of 1:2500, generated on 2014. Recent enough. This was the easy one:
  • Download each file
  • Unzip it
  • In QGIS, Layer→Add Layer→Add Raster Layer (or Shift-Cmd-R)
Since the files are already geolocated data (the format is SID, which is why I needed a special plugin to handle it) in just a few minutes I had a satellite view of the area, automatically placed and multi-scale. Not bad for a few minutes of downloading and goofing around.

Then the real work started: I wanted street names, road names and features. How? I’m pretty sure there are many ways, but the one I found most straightforward was:
  • Download Topography-base maps, with a scale of 1:2500 in SHP (Shapefile) format
  • In QGIS, Layer→Add Layer→Add Vector Layer (or Shift-Cmd-V)
  • Select full folder, Arc/Info binary format and browse to it
  • Select the files you really want
ICC provides a lot of files for each map tile at that resolution. Lots of stuff I didn’t really want. I chose only toponymy, elevation lines, hydrography and roads. Why?
  • I needed toponymy layers to set labels to features
  • Elevation looks very cool (even if I disabled it for the final generated map)
  • With hydrography I could change the colour from the satellite imagery to a more bluish tone in water areas (since the Foix dam is quite greenish)
  • Roads was the main reason I was doing this

Adding some text

Once I had everything in place I wondered: Where are the labels?
  • Double-click a toponymy layer
  • Labels→Label this layer with…
Here some of the huge power of QGIS started to appear. Most “variables” in the map can be controlled via either fields in the data layer OR functions applied to these fields. So, I could easily label by a data column, like TEXT_TOP (which had the common name of the feature, like Pantà de Foix.) But I also could set the size of the font to the one defined in the datafile. And I could even choose the font according to the feature type (or in my case, the font defined in the data file: the data provided by the ICC had font size and font family for the features) with a function!

WHEN "FONTNAME" LIKE 'Times New Roman' THEN 'Georgia'
WHEN "FONTNAME" LIKE 'Arial Narrow' THEN 'Futura'
WHEN "FONTNAME" LIKE 'Courier New' THEN 'Inconsolata'

The language seems to be QGIS specific, but has SQL-like LIKE. Single quotes denote strings, double quotes denote fields. Important to remember, since it’s very easy to mix one with the other without realising. I set all labels to show, even colliding labels. I didn't want to miss a castle or church because it was too close to a large street. I'd rather have overlapping labels in this case.

Then I decided I wanted something more: I wanted icons to show what each feature was. Icons like what you have in a normal map, where churches are indicated by a cross and castles by a tower. The layer I was working with (the toponymy layer) only had type codes for its features, so I couldn’t really tell what a 23 was. Church? Castle? Farm?

Symbols…? Labels...?

To do this, I needed to download an auxiliary file (which the ICC already told me about when I clicked Shapefile as type of download) having the list of code together with human-readable definitions. It is loaded as a single-file Shapefile layer, but has no “visible data.” Instead you need some magic.
  • Open a toponymy layer
  • Select Joins
  • Add a join layer with codis_topo (the source, in this case the layer I just added) and selecting as join field the type code (in this case, CODI_TOP)
  • I disabled caching and added a custom name to the newly created column, the join

A join
With this at least I’d know, since the type was now human-readable. I still didn’t know how to add icons, but I could edit the name and add a letter to denote what it is (or I could even add some text.) The labelling function is then

WHEN "coditopo_03ca_CONCEPTE" LIKE '%capella%' THEN CONCAT( '† ', "TEXT_TOP" )
WHEN "coditopo_03ca_CONCEPTE" LIKE '%monestir%' THEN CONCAT( '† ', "TEXT_TOP" )
WHEN "coditopo_03ca_CONCEPTE" LIKE '%monestir%' THEN CONCAT( '† ', "TEXT_TOP" )
WHEN "coditopo_03ca_CONCEPTE" LIKE '%tedral%' THEN CONCAT( '† ', "TEXT_TOP" )
WHEN "coditopo_03ca_CONCEPTE" LIKE 'Església' THEN CONCAT( '† ', "TEXT_TOP" )
WHEN "coditopo_03ca_CONCEPTE" LIKE 'Convent' THEN CONCAT( '† ', "TEXT_TOP" )
WHEN "coditopo_03ca_CONCEPTE" LIKE 'Temple' THEN CONCAT( '† ', "TEXT_TOP" )
WHEN "coditopo_03ca_CONCEPTE" LIKE 'Arc' THEN CONCAT( 'fl ', "TEXT_TOP" )
WHEN "coditopo_03ca_CONCEPTE" LIKE '%ducte' THEN CONCAT( 'fl ', "TEXT_TOP" )
WHEN "coditopo_03ca_CONCEPTE" LIKE 'Font, bullidor, deu' THEN CONCAT( 'ƒ ', "TEXT_TOP" )
WHEN "coditopo_03ca_CONCEPTE" LIKE '%toll,%' THEN CONCAT( '≈ ', "TEXT_TOP" )
WHEN "coditopo_03ca_CONCEPTE" LIKE '%astell,%' THEN CONCAT( 'Ħ ', "TEXT_TOP" )
WHEN "coditopo_03ca_CONCEPTE" LIKE 'Talaia, torre de defensa, torre de guaita' THEN CONCAT( 'Ħ ', "TEXT_TOP" )
WHEN "coditopo_03ca_CONCEPTE" LIKE '%rica (en%' THEN CONCAT( 'Ħ ', "TEXT_TOP" )
WHEN "coditopo_03ca_CONCEPTE" LIKE 'Muralla' THEN CONCAT( '= ', "TEXT_TOP" )
WHEN "coditopo_03ca_CONCEPTE" LIKE 'GR (Sender de Gran Recorregut)' THEN CONCAT( 'GR: ', "TEXT_TOP" )
WHEN "coditopo_03ca_CONCEPTE" LIKE 'PR (Sender de Petit Recorregut)' THEN CONCAT( 'PR: ', "TEXT_TOP" )
WHEN "coditopo_03ca_CONCEPTE" LIKE 'Pou%' THEN CONCAT( 'ů ', "TEXT_TOP" )
WHEN "coditopo_03ca_CONCEPTE" LIKE '%pont%' THEN CONCAT( 'π ', "TEXT_TOP" )

This, basically adds a weird symbol to the text, so, for instance, bridges have a π symbol in front. Not great, but I actually printed it like this for a starter and it looks pretty decent. Here you can see a zoom in and the general view:

The general view

A zoom
In the zoom you can see the glyphs for a fountain (Font d’Horta and Font de Mas Carlús), a church (Sant Pere) an aqueduct (de les Aigües de Vilanova i la Geltrú) and a bridge (de la font d’Horta.) This was nice but non-optimal. I wanted symbols! So, how do you get symbols if you have a toponymy layer with lines, not feature points?


First, duplicate the layers holding the labels. It can be done without duplicating, but it introduces a layer of complication for the human… So, if your computer doesn’t mind the extra layers, it is easier for you as human to have a separate layer for the labels and a layer for the icons.

Once you have duplicated the layer, change its style to rule-based, and add marks following rules with the add sign. For instance, this is the rule I use for Castell (castle):

WHEN "coditopo_03ca_CONCEPTE" LIKE 'Castell,%' THEN 1

with SVG marker svg/fortress2.svg

NOTE: if you are using only one condition, for rule-based markers you can just keep it at

"coditopo_03ca_CONCEPTE" LIKE 'Castell,%'

since it will just return 0 or 1 as needed. You'll only need CASE when you have several types going to the same marker. Since I just copy-pasted most of my code I didn't mind the extra cruft. Thanks to Nathan Woodrow, one of QGIS' developers for pointing it out on twitter.

To add this as image you need to select Marker, then SVG marker. I found very nice SVG icons here, so I use this opportunity as credit (since the printed map is just for my personal use.) And indeed, you need to add as many rules as icons you have. That’s life. A GIS professional probably knows other ways, I’m just a newbie. Once you have all the rules you want, you can copy-paste them in all the layers. Actually, I think all this map business would have been easier merging all vector layers before doing anything else, but since I didn’t do it from the beginning it was hard to do it now. You can find how to merge vector layers in this StackOverflow question.
This is how Style should look like with rule-based

And this is what a specific rule looks like
 After adding markers you’ll need to tweak them. I did one part in SVG (adding stroke to the shapes and changing colours directy in the file so I didn’t need to bother in QGIS) and some others relating to placement (middle point and then changing size and baseline of the icon.) I also did some changes editing the file directly in Emacs, since QGIS files are just XML and replacing is much faster without clicking anything, once you know how the fields are named. The end result? Here you can see the same area as above with icons.

A zoom in with markers in place

Nice, don’t you think?

So, how do you print it?

This is actually very very easy. To print you need a New print composer from the Project menu. This is a set of rules to print some map. So, you choose the paper size and then add pieces to the layout. The basics are a map, a scale and some text, or at least this is the bare minimum I wanted. 

Once you have the map area you can change scale, drag around and change many things, it’s awesome. I decided to use 1:10000 since fitting the whole map in the map area I chose was 1:9556 and I’d rather have a round number and lose some map around the borders. Ready to export to PDF and bring to a printing place. You can also generate a JPG file, but beware of trying to open a 176 Mb with an iPad (even if it is an Air.) It won’t zoom. On the other hand, for my Mac it was much easier to open and zoom/navigate a huge JPG rather than a huge PDF file. Also keep in mind large maps take a long time to export: if you are making tests disable as many layers as you can really manage.

The map composer reminds me of Scribus
Since I wanted a portable version of the map to have on my iPad Air, I decided to split it using ImageMagick in 9 tiles I could easily zoom in any app. IM has the nice “crop” feature that can generate tiles, like:

convert -crop 4x3 MEGAMAP.jpg megamap/tiles%03d.jpg

The problem is that this takes way, way longer than expected, because the image is too big. The fastest way is instead to use the stream command to generate raw RGB data and convert that to JPG. So, repeating 9 times stuff like:

stream -extract 5566x3937+11132+7874 MEGAMAP.jpg t9.rgb
convert -depth 8 -size 5566x3937 rgb:t9.rgb t9.jpeg

Since I only needed to do it this time I didn’t bother to code it as a bash for loop or anything. Whereas convert was taking more than 12 hours to do anything, stream took 3 minutes, counting the time I needed to compute the pixel shifts and the conversions. And probably even the time it took me to create a index.html with the pieces to zoom.

What’s the takeaway of this post? Doing maps is fun, and using QGIS is not that hard as it may seem. And yes, I have an awesome big map now.
-1:-- Using QGIS to create a custom map (Post Rubén Berenguel ( 19, 2015 11:13 AM

Julien Danjou: Timezones and Python

Recently, I've been fighting with the never ending issue of timezones. I never thought I would have plunged into this rabbit hole, but hacking on OpenStack and Gnocchi I felt into that trap easily is, thanks to Python.

“Why you really, really, should never ever deal with timezones”

To get a glimpse of the complexity of timezones, I recommend that you watch Tom Scott's video on the subject. It's fun and it summarizes remarkably well the nightmare that timezones are and why you should stop thinking that you're smart.

The importance of timezones in applications

Once you've heard what Tom says, I think it gets pretty clear that a timestamp without any timezone attached does not give any useful information. It should be considered irrelevant and useless. Without the necessary context given by the timezone, you cannot infer what point in time your application is really referring to.

That means your application should never handle timestamps with no timezone information. It should try to guess or raises an error if no timezone is provided in any input.

Of course, you can infer that having no timezone information means UTC. This sounds very handy, but can also be dangerous in certain applications or language – such as Python, as we'll see.

Indeed, in certain applications, converting timestamps to UTC and losing the timezone information is a terrible idea. Imagine that a user create a recurring event every Wednesday at 10:00 in its local timezone, say CET. If you convert that to UTC, the event will end up being stored as every Wednesday at 09:00.

Now imagine that the CET timezone switches from UTC+01:00 to UTC+02:00: your application will compute that the event starts at 11:00 CET every Wednesday. Which is wrong, because as the user told you, the event starts at 10:00 CET, whatever the definition of CET is. Not at 11:00 CET. So CET means CET, not necessarily UTC+1.

As for endpoints like REST API, a thing I daily deal with, all timestamps should include a timezone information. It's nearly impossible to know what timezone the timestamps are in otherwise: UTC? Server local? User local? No way to know.

Python design & defect

Python comes with a timestamp object named datetime.datetime. It can store date and time precise to the microsecond, and is qualified of timezone "aware" or "unaware", whether it embeds a timezone information or not.

To build such an object based on the current time, one can use datetime.datetime.utcnow() to retrieve the date and time for the UTC timezone, and to retrieve the date and time for the current timezone, whatever it is.

>>> import datetime
>>> datetime.datetime.utcnow()
datetime.datetime(2015, 6, 15, 13, 24, 48, 27631)
datetime.datetime(2015, 6, 15, 15, 24, 52, 276161)

As you can notice, none of these results contains timezone information. Indeed, Python datetime API always returns unaware datetime objects, which is very unfortunate. Indeed, as soon as you get one of this object, there is no way to know what the timezone is, therefore these objects are pretty "useless" on their own.

Armin Ronacher proposes that an application always consider that the unaware datetime objects from Python are considered as UTC. As we just saw, that statement cannot be considered true for objects returned by, so I would not advise doing so. datetime objects with no timezone should be considered as a "bug" in the application.


My recommendation list comes down to:

  1. Always use aware datetime object, i.e. with timezone information. That makes sure you can compare them directly (aware and unaware datetime objects are not comparable) and will return them correctly to users. Leverage pytz to have timezone objects.
  2. Use ISO 8601 as input and output string format. Use datetime.datetime.isoformat() to return timestamps as string formatted using that format, which includes the timezone information.

In Python, that's equivalent to having:

>>> import datetime
>>> import pytz
>>> def utcnow():
>>> utcnow()
datetime.datetime(2015, 6, 15, 14, 45, 19, 182703, tzinfo=<UTC>)
>>> utcnow().isoformat()

If you need to parse strings containing ISO 8601 formatted timestamp, you can rely on the iso8601, which returns timestamps with correct timezone information. This makes timestamps directly comparable:

>>> import iso8601
>>> iso8601.parse_date(utcnow().isoformat())
datetime.datetime(2015, 6, 15, 14, 46, 43, 945813, tzinfo=<FixedOffset '+00:00' datetime.timedelta(0)>)
>>> iso8601.parse_date(utcnow().isoformat()) < utcnow()

If you need to store those timestamps, the same rule should apply. If you rely on MongoDB, it assumes that all the timestamp are in UTC, so be careful when storing them – you will have to normalize the timestamp to UTC.

For MySQL, nothing is assumed, it's up to the application to insert them in a timezone that makes sense to it. Obviously, if you have multiple applications accessing the same database with different data sources, this can end up being a nightmare.

PostgreSQL has a special data type that is recommended called timestamp with timezone, and which can store the timezone associated, and do all the computation for you. That's the recommended way to store them obviously. That does not mean you should not use UTC in most cases; that just means you are sure that the timestamp are stored in UTC since it's written in the database, and you check if any other application inserted timestamps with different timezone.

OpenStack status

As a side note, I've improved OpenStack situation recently by changing the oslo.utils.timeutils module to deprecate some useless and dangerous functions. I've also added support for returning timezone aware objects when using the oslo_utils.timeutils.utcnow() function. It's not possible to make it a default unfortunately for backward compatibility reason, but it's there nevertheless, and it's advised to use it. Thanks to my colleague Victor for the help!

Have a nice day, whatever your timezone is!

-1:-- Timezones and Python (Post Julien Danjou)--L0--C0--June 16, 2015 05:39 PM

Bozhidar Batsov: CIDER 0.9

CIDER 0.9 is finally out and it’s our best release yet (believe it or not)! It took a lot more time than I originally anticipated, but at least we managed to ship in time for EuroClojure!

There are a ton of important changes and new features in 0.9 and now I’ll go quickly through some of them.


Believe it or not CIDER now has a debugger! This was like the most requested feature ever, so I’m sure at least some of you are excited. The debugger was developed by the awesome Artur Malabarba. He even wrote a post about it and I guess you should read it.

Dependency isolation

CIDER’s dependencies will no longer affect your projects (read this as introduce dependency conflicts in them). All the dependencies are now isolated using source rewriting (simply put – they live in different namespaces than the original libraries). This magic is done by mranderson. Thanks to Benedek Fazekas for creating this small but super helpful tool!

Rich code completion

Completion candidates are now annotated with information about the namespace and the type of the thing being completed. It’s pretty neat.

The screenshot above features company-mode. The annotations are not supported in auto-complete-mode (that’s a limitation of AC, not a limitation of CIDER).

Misc additions

Here’s a short list of other important additions:

  • Support for Piggieback 0.2
  • New code formatting commands (based on cljfmt)
  • New EDN data formatting commands


There were also a few important changes. Most notably we had to kill source-tracking code evaluation, as it wasn’t playing nice with ClojureScript. This was also a hacky solution and I still hope than one day this will be properly supported in nREPL itself. In simple terms – var definitions evaluated by themselves won’t have any location metadata set for them, which will make it impossible to go their definition. You can also help out by voicing your support for this nREPL ticket’s patch to be merged.

You’ll also notice that some commands that didn’t prompt for confirmation in the past do so now (e.g. find-var). This was done mostly for consistency with Emacs’s own commands that do similar things. The behavior is configurable via cider-prompt-for-symbol. If a ton of people dislike the new defaults reverting them is on the table.

All the Gory Details

There were truly a ton of changes and there’s little point in me repeating them here. If you want to know everything have a look at the release notes.

The Road Ahead

Going forward our top priority will be merging some functionality from refactor-nrepl and clj-refactor into CIDER itself. Think of things like find-usages, extract-definition, etc. Refining the debugger will be another top priority.

We’ll also try to do some important internal changes:

Depending of how well we progress on those tasks the next release will be either 0.10 or 1.0. I won’t make any commitments about its release date (but judging from past it will likely be 3 to 6 months from now).

If you’re wondering why things are moving more slowly lately, here’s the answer for you – I’ve been super busy since the beginning of the year and haven’t had much time for open-source projects. I’m hoping this will change, but only time will tell. I’m very happy that a lot of people contributed to the development of CIDER 0.9. The project definitely doesn’t have a bus factor of one. :–)

Special thanks to Michael Griffiths who did a ton of great work on this release. You rock!

P.S. Recently I talked on the Cognicast about CIDER (in general and 0.9 in particular). You might find this episode interesting.

P.P.S. I’m rarely on IRC these days. #cider on slack and our gitter channel are the official CIDER chats as far as I’m concerned.

-1:-- CIDER 0.9 (Post)--L0--C0--June 16, 2015 12:59 PM

Ivan Kanis: someday


appt improvements

add popup. redo multi appointment patch without refactoring

-1:-- someday (Post Ivan Kanis)--L0--C0--June 11, 2015 03:04 AM

Ivan Kanis: maybe


climb old man of hoy

write clippy.el

i♥emacs emacs for beginners


The first section is where I capture stuff. My weekly review is a natural process. I start at the top and type 'w' to refile. Using speed keys really help. If you don't know about it check out the documentation in the function org-speed-command-help.

Then I go through each section and see what needs to be done. I tried to be ruthless and put stuff in someday or maybe so that my list is current and feels fresh.

I then finish with things that are in someday (one day I will do it) to maybe (who knows?).

That pretty much sums up how I implement GTD with org mode.

-1:-- maybe (Post Ivan Kanis)--L0--C0--June 11, 2015 03:04 AM

Michael Fogleman: 2014: A Year of Emacs

My Emacs "birthday" is January 21, 2014. That's right-- I just started using Emacs this year! While it's not quite my one-year birthday, I thought I'd take advantage of the annual review blogging tradition to do a retrospective on my first year in Emacs. Note: much of the following chronology takes place during an extended romp through Asia.

I installed Arch Linux in the Fall of 2013. When using Linux, you often need to edit configuration files. The friend who helped me set me up with Vim. I learned the basics--how to insert, save, and quit--and not much else.

Arch on a bench

In January, I decided it might be fun to give Emacs a try. Here is a picture of Marina Bay in Singapore, taken just before or while I did the Emacs tutorial:

Marina Bay in Singapore, just before or during my Emacs birth

As a life-long user of keyboard shortcuts, I appreciated Emacs' notation for key bindings. The tutorial begins with basic cursor controls; easy enough, but nothing exciting. I could see the line, sentence, and buffer equivalents being useful. But my jaw dropped when it taught me C-t, transpose-chars. I knew that mastering just that command would probably save me a lot of pain and typos, and that was probably the least of what Emacs could do.

While the Emacs tutorial probably isn't meant to take more than an hour or two on the first try, it took me probably twice as long. This was because I made Anki cards. Some people say that Emacs' learning curve is steep. For myself, I've found Emacs' learning curve to be gentle, but (pleasantly) endless. Then again, it was probably making Anki cards that made the learning curve less steep for me.

A variation of this card was probably one of my first Emacs cards:

Anki card: transpose-chars 1

Cloze deletion cards like this one are very convenient for this kind of thing. One reason is that it's easy to add new, related information later:

Anki cards transpose-chars 2

In February, the battery on my little Arch laptop died. I spent most of the month without a laptop, waiting for a new battery to arrive by mail. I borrowed my friend and travel partner's machine to review my Anki cards. Still, I did manage to have a little time to develop my Emacs-fu.

In Hanoi, the hotel room we stayed in had a (virus-ridden) Windows machine. What else could I do but install Emacs? At this time, my Emacs configuration was not that complex, so it wasn't worth adapting. As it turned out, that time with a bare Emacs proved especially helpful for mastering some of the key Emacs concepts that I hadn't quite made use of yet; in particular, I got the hang of using multiple buffers in one session. By the the end of February, my new battery had arrived, and I was back in the Emacs saddle.

In March, I converted my my Emacs configuration to an Org-literate format, and started tracking it with Git. This was really the first project that I used Git for, and it gave me an opportunity to learn Git.

The other highlight of March was starting to learn a little Elisp. I found Robert Chassell's "An Introduction to Programming in Emacs Lisp" especially helpful. Chassell's overview and Org-mode's fantastic documentation helped me to write my first significant piece of Elisp (some org-capture templates).

April started off with a bang when my Emacs configuration was featured in a major motion picture, Tron Legacy. But that wasn't nearly as exciting as making my first major mode, tid-mode.

In late June, Artur Malabarba launched his Emacs blog, Endless Parentheses. One of his early posts was about hungry-delete. I was excited about it, but found that it did not work with transient-mark-mode. Artur encouraged me to write a fix. I was very excited when Nathaniel Flath, the maintainer, agreed to merge my patches into hungry-delete. At about the same time, Artur posted an adapted version of my narrow-or-widen-dwim function to Endless Parentheses. Sacha Chua, Nathaniel Flath, and some other Emacs Lisp hackers also offered suggestions.

At the end of July, I started learning Clojure, and added an initial CIDER configuration. While reading the Clojure Cookbook, I decided to hack out a function that turned the pages. Ryan Neufeld, one of the co-authors, merged my pull request, and a while later, I saw my function mentioned on Planet Clojure.

In October, I purchased a Mac for a Clojure contracting job. (Knowing Emacs helped me get the job!) Adding the :ensure keyword to my use-package declarations made the Emacs configuration portion of my OS X set-up process near-instant and pain-free. It was a really cool feeling to be using the same Emacs configuration on two different machines. By the end of the month, both were running on the newly-released Emacs 24.4.

Once Emacs 24.4 was out, Artur posted an Emacs 25 wishlist to Endless Parentheses. I responded with this tweet:

This tweet indirectly led to the happy occasion of the Emacs Hangouts.

That just about brings us to this post. In retrospect, I can't believe it's been less than a year, or that I've learned so much. Thanks to everyone who has helped me so far on the endless path of mastering Emacs, especially Ben, Eric, Sacha Chua, Artur Malabarba, and Bozhidar Batsov.

Joseph Campbell was a Lisp guru

I want to close this post out with Sacha's tweet about 2015:

Like Sacha, I want to learn how to write and run tests in Emacs. I want to learn more about org-mode's features and possible workflows. More broadly, I'd like to make more posts about Emacs, and find other ways to contribute to the Emacs community. I'd like to learn more about Emacs core development. In terms of contrib, I'd like to help accelerate the release of Magit's "next" branch. Above all, I'm sure I'll keep tweaking my configuration.

-1:-- 2014: A Year of Emacs (Post Michael Fogleman)--L0--C0--June 11, 2015 03:02 AM

Michael Fogleman: Emacs can keep in touch

I've wanted to show a specific Emacs workflow that I've established at the Emacs Hangouts that I've attended, but thought it might require too much explanation for an Emacs Hangout. Hence, this post. You might be interested in this workflow if you regularly edit a specific text file in a particular way, run an external program with the same parameters. You might also get some ideas if you're an Emacs-wielding programmer, and wish Emacs had some particular functionality, but would prefer to use Bash or another language to give it that functionality.

Some time ago, my friend Ben started working on a side project called "Keep In Touch." The premise: you have friends, family, and acquaintances that you'd like to stay in touch with. You maintain a list of those people, how often you'd like to contact them, and when you last contacted them. Keep In Touch can then figure out who you are out of touch with. For example, if you want to talk to someone every 30 days, but it's been 31 days, then you are out of touch with them, and the program tells you so. Simple!

Since I started using the program, I've fallen in love with using it. It has helped me to stay in touch with more people, more often. Moreover, I re-implemented Keep in Touch in Clojure as an exercise. And while Keep in Touch provides a serviceable CLI, I've worked out a simple Emacs interface for maintaining the database and viewing the program's output.

It all starts with telling Emacs where it can find the database:

(setq keepintouch-datafile "~/Dropbox/")

Next, I needed a way to tell Emacs that I had contacted someone. The result is an interactive function that asks you who you contacted. It ordinarily assumes that you contacted the person today, but with a prefix argument, it asks you for an alternate date. Then it opens the file and makes the appropriate changes.

(defun keptintouch (arg)
  "Request a contact in a file, and update their last
  contacted date (either today, or, if a prefix is supplied, a user-supplied date.)"
  (interactive "P")
  (let ((contact (read-string "Who did you contact? "))
        (date (if (equal arg nil)
                  (format-time-string "%Y/%m/%d")
                (read-string "When did you contact them? (year/month/date): "))))
      (find-file keepintouch-datafile)
      (goto-char (point-min))
      (search-forward contact)
      (forward-line -1)
      (insert date)
      (switch-to-buffer (other-buffer))
      (kill-buffer (other-buffer)))
    (message "%s was contacted." contact)))

"keptintouch" uses read-string to ask you who contacted, and, if need be, when you contacted them. It uses format-time-string to format today's date in the appropriate format.

The body of the function works almost like a keyboard macro. Often, you can start writing an Elisp function by hitting "C-h k" (describe-key) and finding out what functions are called when you execute the steps as keystrokes. Another way to do this quickly might be to make the keyboard macro, run edit-last-kbd-macro, and use the function annotations to read their documentation or make pseudo-code.

One reason that this is a function instead of a keyboard macro is that it uses some buffer management functions. (All interactive functions are of course accessible to keyboard macros through keyboard strokes, which can really save you some time in one-off situations!) It opens my Keep In Touch database in a new buffer, finds the contact, edits their last contacted date, saves, closes, and switches the buffers. If all went well, it reports success with message. If for some reason the contact is non-existent, search-forward will throw an error. (If that happens, or I want to view or edit the datafile manually, I find it with ido-recentf-open.)

All of this is wrapped in save-excursion, which is kind of like the shell commands popd and pushd except for buffers. In other words, it does something, and then returns the user to what they were doing before they executed the function.

Now that I had a way to maintain the database, I needed a way to run Keep in Touch and view its output, a sorted backlog of people that you are out of touch with.

The Clojure version of Keep in Touch is designed to be exported to a .jar file. Running the resulting program from the command line looks like this:

# note the special location of the .jar
cd target/uberjar
java -jar keepintouch-0.1.0-SNAPSHOT-standalone.jar ~/Dropbox/ schedule backlog

I decided to look at shell-command's documentation to find a way to run this command and put the results into an output buffer. As it turns out, shell-command is that function. As expected, it takes an argument for the desired shell-command. But it also allows for two optional arguments: the name of an output buffer, and the name of an error buffer.

(defun keptintouch-backlog ()
  "Create a buffer with Keep In Touch backlog."
  (let ((src "~/src/keepintouch/clj/keepintouch")
        (jar "-jar target/uberjar/keepintouch-0.1.0-SNAPSHOT-standalone.jar")
        (cur default-directory)) 
    (cd src)
     (concat "java " jar " " keepintouch-datafile " schedule backlog")
     "*Keep In Touch Backlog*")
    (cd cur)))

You'll see that the concat will expand to the shell command that runs the .jar, and that it is followed by an appropriate buffer name.

All of this Lisp makes its way to my finger with two key-binds (by way of use-package's bindkey.el):

(bind-keys ("C-c k" . keptintouch)
           ("C-c K" . keptintouch-backlog))

One variable, two functions, and two keybinds are all it took to make my life easier and get back to staying in touch with friends. You can eat your Emacs cake, and have defun, too.

-1:-- Emacs can keep in touch (Post Michael Fogleman)--L0--C0--June 11, 2015 03:02 AM

Timo Geusch: Improved syntax highlighting with org2blog and custom CSS

As mentioned in an earlier post, I changed my blogging workflow to org2blog for writing and editing posts in Emacs and only push them up to my WordPress blog when the posts are almost done. I still do the final editing in WordPress so I can tweak the SEO settings and all that, but the… Read More »

The post Improved syntax highlighting with org2blog and custom CSS appeared first on The Lone C++ Coder's Blog.

-1:-- Improved syntax highlighting with org2blog and custom CSS (Post Timo Geusch)--L0--C0--June 10, 2015 10:08 AM

linek posted a photo:

-1:--  (Post linek ( 08, 2015 07:39 PM