Save Org Structure as Directory and Files

Marco Wahl posted a gist that saves an Org file structure as a series of directories and files. I have no idea what I’d use this for but it’s pretty neat.

Posted in General | Tagged , | 3 Comments

Zamansky 21: Web Mode

Mike Zamansky has another video in his Using Emacs Series up. This time it’s about web-mode. Happily, Org export writes almost all of my HTML for me these days but if you find yourself writing HTML/CSS more than occasionally, web-mode is for you.

As Zamansky says, it’s much better than html-mode. It takes care of the usual syntax highlighting as well as closing tags, folding, indentation, navigation, and other such things. The best place to get more information on the mode is its Web page. In particular, see the section on Native Features for a list of all the things it can do. The Web page also has a nice cheat sheet of the mode’s shortcuts.

Fortunately, web-mode is available from Melpa (and Melpa Stable) so you don’t need to worry about downloading it yourself. Zamansky has a nice beginning configuration for web-mode on the video page so take a look at that as well as the documentation on Web Mode’s web page.

The video is only 7 minutes, 49 seconds long so it shouldn’t be hard to find time to watch it.

Posted in General | Tagged | Leave a comment

Cables

We have it pretty good these days. Not very long ago cables were everywhere and they were always breaking and otherwise causing problems. These days we are relatively cable-free. We still have power cables, of course, and cables for a few older peripherals but mostly cables have been replaced by WiFi and Bluetooth. Apple is even trying to get us to give up the cables to our earphones.

Still, it seems we still carry cables around even if they’re mostly power cables. Yesterday, a series of articles on workshifting popped up in my feed. Two of these deal with techniques for managing cables. One talks about managing your cables at home. The other talks about dealing with cables when you travel. Both articles are short and well worth reading if only to see how others have solved these problems.

The articles both appear on the Workshifting blog. This is a very nice resource for those of us who work from home or on the road. Sadly, it hasn’t been very active lately but it’s worth taking a look at its archives. The scarce posting is a result, I presume, of workshifting going mainstream. Ten or fifteen years ago when the concept was still new people needed help and advice on how to manage their work environment and what devices they needed. Now workshifting is so common that we seldom even hear the term. It’s just how we work.

In any event, if you want a bit of advice on how to deal with cables, take a look at these two excellent articles.

Posted in General | Tagged | Leave a comment

Word Counting in Org Mode

If you do your writing in Org mode and like to maintain a running word count—especially useful for professional writers and students assigned an \(n\) word paper—Angelo Basile has a nice tip on how to install a word count function to your org buffers.

I temporally installed and enabled wc-mode for this post to see how it works and it seems like an excellent solution if you’re looking for something to keep track of your word count. The exact format of the display is customizable (of course) but the default seems reasonable. Here’s the defcustom from wc-mode.el:

(defcustom wc-modeline-format "WC[%W%w/%tw]"
  "The format string for the modeline.
The detailed information for this minor mode can be shown in many
ways in the modeline. The formatting strings recognized in this
format are as follows.

  %W  Original word count (before changes)
  %L  Original line count
  %C  Original character count
  %w  Change in words
  %l  Change in lines
  %c  Change in characters
  %gc Character change goal
  %gl Line change goal
  %gw Word change goal
  %tw Total words in buffer
  %tl Total lines in buffer
  %tc Total characters in buffer

The default modeline, WC[%W%w/%tw], will display the original number
of words followed by the change in words (delta), followed by the total
number of words in the buffer.
It will looks something like WC[742+360/1100] in the modeline.
"

As you can see, the display is very flexible and can display just about any word-count-type information you want. If you don’t want the word count in every Org buffer, don’t include the add-hook in your configuration and just call wc-mode when you to turn it on.

UPDATE [2017-05-03 Wed 12:21]: Fixed link.

Posted in General | Tagged , | 5 Comments

Zamansky 20: Yanking and Auto Revert

Mike Zamansky has another video up in his Using Emacs Series. This time he provides a video demonstration of counsel-yank-pop that I wrote about previously here on Irreal. As always, things seem clearer and easier to understand when you see it actually happen.

The other thing that Zamansky covers is auto-revert-mode. It checks if the file you are looking at in Emacs has changed on disk and reloads it if so. If you’re working with a single machine that doesn’t seem very useful or even to make sense1 but it’s really useful when you work on more than a single computer.

To see how it can really help your workflow, let’s assume you work on two separates machines—one at work, one at home, say. In order to keep files synced, you use something like Dropbox. Then when you save a file at work, it also updates your machine at home. The problem occurs when you already have the file open in Emacs on your home machine. Now the on-disk copy and the in-buffer copies differ and it’s easy to get a conflict. This is the exact situation auto-revert-mode fixes. When Emacs sees the file change on disk, it automatically reloads the buffer so that when you come back to your home machine you’ll be working with an up-to-date copy of the file.

Footnotes:

1

It can even be useful on a single machine if you have an external process that occasionally updates a file you’re examining in Emacs—a system log file, for example.

Posted in General | Tagged | 1 Comment

Zamansky 19: Conditional Loading of Emacs Config

Mike Zamansky has another video in his Using Emacs Series. This video addresses a problem he has while making the videos. A theme of the series is building an Emacs configuration. Each video considers 1 or 2 packages or features and how to configure and use them. The problem is he needs his entire configuration to get his other work done and it’s a pain to move between the partial and complete configurations.

Zamansky solves this problem by conditionally loading the rest of his configuration. Thus, he can put the partial configuration on GitHub for anyone who’s following along to use but when he uses it for his real work, the rest of his configuration will be loaded. The only wrinkle is what to do if the rest of the configuration is not present as will be the case when those following along at home use his config. His solution is to wrap the loading of the rest of his configuration in an if statement that tests if the file is present:

(defun load-if-exists (f)
  (if (file-readable-p f)
      (load-file f)))

Then he can conditionally load other files with

(load-if-exists "some-file.el")

This has the additional benefit of introducing a bit of Elisp, something that every serious Emacs user will eventually have to get comfortable with.

Most of us won’t have this problem but it does show how to conditionally load files, something that’s useful for us all. Here, for example, is how I load OS and machine specific configuration items

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Pull in system and platform specific configurations                    ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Just keep on going if the requisite file isn't there.
;; Manipulations in second load is for "gnu/linux" --> "linux"

(load (car (split-string (system-name) "\\.")) t)
(load (car (reverse (split-string (symbol-name system-type) "/"))) t)

Using load with a second argument of t is functionally equivalent to Zamansky’s load-if-exists.

This is a short video so there’s no reason not to watch it. Even if you’re an experienced Emacser, it’s interesting to see how others solve common problems.

UPDATE [2016-11-12 Sat 12:16]: loadload-file

Posted in General | Tagged | 2 Comments

Org Mode and Python

If you’re a Python user and like to put Python snippets in source blocks in an Org mode file, John Kitchin has some very nice enhancements for you. Kitchin, as Irreal readers surely know by now, is a Chemical Engineering researcher at Carnegie Mellon. He does a huge amount of his work with Org and frequently embeds Python code in Org buffers. Some of this Python is long-running and therefore freezes Emacs because Babel runs the code synchronously.

Part of Kitchin’s enhancement fixes that by arranging for the code to run asynchronously so that you can do other work while the code is running. That’s actually something he figured out a while ago. What’s new is better error handling and a way to look at the results produced so far. His students complained that it’s hard to find the offending line from a stack trace in case of an error. Kitchin’s latest fix solves this by arranging for temporary line numbers to be put in the source block and for the cursor to go to the line that raised the error when it occurs. He also provides a link that you can click on to kill the running code if you need to.

Finally, he wraps autopep8 and pylint is emacs functions so that you can easily reformat code and check for syntax violations before you run it.

All of this is part of his Scimax distribution but this new code has not yet been merged into the master branch because he doesn’t want to change things mid-semester. He plans on merging it in Decemeber but gives a link to the experimental branch if you want to try it out now.

Posted in General | Tagged , | Leave a comment

isearch Tutorial

Bastien Guerry has a nice tutorial on isearch available on his M-x doctor RET site. Unless you’re really an expert on isearch, there’s a lot you don’t know about it. You can, for example, search for the word or character at point. You can ignore multiple spaces so that they get treated the same as one space.

There are many more shortcuts that you probably didn’t know about. Rather than list them all, I’ll just list these items that Guerry says he wishes he had known about sooner:

Ctrl+s Meta+e Edit search string
Ctrl+s Ctrl+w Search for word at point
Ctrl+s Meta+r Toggle regex search
Ctrl+s Meta+s o Run occur on the search string
Ctrl+s Ctrl+Meta+i Complete the current search string

There’s lots more so be sure to take a look at Guerry’s post.

UPDATE [2016-11-10 Thu 19:51]: Fixed key sequence for search word at point.

Posted in General | Tagged | 3 Comments

Better Kill Ring Manipulation

Yesterday, I wrote about Ben Maughan’s tip for maintaining the clipboard over an Emacs kill. If you read Maughan’s post you’ll see that there’s a link to a post on cycling through your Emacs kill ring. I remember seeing this before but it didn’t register. After reading his post on the clipboard, I reread the post on the kill ring and realized that it resolved a long standing irritant for me.

We all know about yank-pop to yank older items on the kill ring but I always felt as if I were flying blind because you can’t see what you’re going to get until you run the command. There was also the problem that if you wanted an old entry you had to first do a normal yank before you could step back through the older entries. Abo-abo’s counsel-yank-pop solves both these problems.

If you bind counsel-yank-pop to Meta+y, you can bring up a menu containing the kill-ring entries and just choose whichever one you want in the usual Ivy way. Filtering and scrolling work just as they always do with Ivy. Maughan’s post describes a small tweak that allows you to repeatedly type Meta+y, to move back in the list. I’m perfectly happy to scroll with Ctrl+n and Ctrl+p so I didn’t bother with that.

This is the second of two packages that I’ve written about recently that transform the kill ring from being annoying to use to simple and enjoyable. The first is undo-tree and the second is counsel-yank-pop (well, really ivy and counsel). If you don’t have them installed, you really should consider it. They will, I promise you, make your life simpler.

Posted in General | Tagged | 8 Comments

Maintaining the System Clipboard Over an Emacs Kill

Ben Maughan has a nice tip for Clipboard/Emacs Kill Ring interaction. In recent versions of Emacs at least, you can yank the value of the system clipboard as long as nothing has been put in the kill ring since the time that the value in the clipboard was set. That works well and I often use it to copy some text from, say, a Web page and then yank it into an Emacs buffer.

The problem is that if you kill something in Emacs in the meantime, the clipboard value is lost because it’s not actually added to the kill ring. Maughan gives us a one-line fix that causes the clipboard to be pushed onto the kill ring if necessary. That means that you can still retrieve it even if there’s an intervening kill. That’s really handy. I often copy text from the browser, return to Emacs, do some editing that involves a kill, and then end up having to copy the text from the browser again. With this fix, it’s still in the kill ring and retrievable. Very nice. I wish I’d known about this sooner.

Posted in General | Tagged | Leave a comment