Posts

  • Spell Checking Comments

    I’m notorious for all the typos I make.1 Thankfully Emacs features an awesome built-in mode named flyspell to help poor typists like me. Flyspell highlights misspelled words as you type (a.k.a. on the fly) and has useful keybindings to quickly fix them.

    Most people typically enable flyspell only for major modes derived from text-mode (e.g. markdown-mode, adoc-mode), but it can really help programmers as well by pointing out typos they make in comments. All you need to do is enable flyspell-prog-mode. I typically enable it for all programming modes2 like this:

    (add-hook 'prog-mode-hook #'flyspell-prog-mode)
    

    Now you’ll get instant feedback when you make some typo in a comment. To fix a word just press C-c $ (M-x flyspell-correct-word-before-point), while your cursor is behind it.3

    flyspell_prog_mode.gif

    That’s all I have for you today! Keep fixing those nasty typos!

    1. Especially in blog posts. 

    2. At least the well-behaved ones that derive from prog-mode that is. 

    3. There are many other ways to correct misspelled words with flyspell, but we’ll ignore them for now for the sake of simplicity. 

  • Dealing with Jekyll Post URLs

    A while ago I wrote about migrating Emacs Redux from Octopress to Jekyll. While I’m really happy with Jekyll overall, there has always been one thing that frustrated me a bit - namely linking to other posts. The syntax for this is the following:

    
    {% post_url name-of-post %}
    
    

    I know this probably doesn’t seem like a problem, but posts in Jekyll are usually prefixed with a timestamp (e.g. 2019-05-21-some-post ) which makes it really hard to get the name right without consulting the list of posts first. Luckily for us it’s trivial to write an Emacs command that helps with this.

    
    (defun jekyll-insert-post-url ()
      (interactive)
      (let* ((files (remove "." (mapcar #'file-name-sans-extension (directory-files "."))))
             (selected-file (completing-read "Select article: " files nil t)))
        (insert (format "{%% post_url %s %%}" selected-file))))
    
    

    Here’s how this command looks like in action:

    jekyll_post_url.gif

    I don’t know you, but I’m totally loving this. You can easily extend the core idea for all sorts of similar tasks that require transforming a bit the files in the current directory. Here’s a similar helper for dealing with image URLs:

    (defun jekyll-insert-image-url ()
      (interactive)
      (let* ((files (directory-files "../assets/images"))
             (selected-file (completing-read "Select image: " files nil t)))
        (insert (format "![%s](/assets/images/%s)" selected-file selected-file))))
    

    Let’s see this in action:

    jekyll_image_url.gif

    That’s all I have for you today! Meta-X forever!

  • Emacs Prelude Gets a User Manual

    This is going to be a really short post.

    For ages I’ve planned to create a user manual for Emacs Prelude, but I never got to doing so. Writing a good manual is a huge amount of work and I was wary (and lazy) to commit to doing it. Today I realized that probably having some manual (even if it’s not good) beats having no manual, so I quickly sliced and diced the old huge README of the project, and compiled it together into this proto-manual.

    I’ll try to find some time to improve it, but I can make no promises. You can certainly help me out by working on the manual yourselves, though. Prelude is pretty simple, so I assume that everyone, who has spent a bit of time using it, is more than qualified to work on improving its documentation. By the way, the manual features a dedicated section for working on the manual! Coincidence? I don’t think so.

    Keep hacking!

  • The Emacs Year in Review

    This post is a brief summary of the past year for Emacs from my perspective.

    Read More
  • Convert a Keyword to a Symbol

    Recently I needed to convert keywords into symbols in Emacs Lisp and I noticed there was no built-in function for this, so I’ve decided to build one myself. Here’s my approach:

    (defun keyword-to-symbol (keyword)
      "Convert KEYWORD to symbol."
      (intern (substring (symbol-name keyword) 1)))
    
    (keyword-to-symbol :foo) ; => 'foo
    

    It’s extremely simple really - using the fact that keywords in Emacs Lisp are actually symbols we can convert them to a string with symbol-name, drop their leading : and then convert them back to symbols.

    For me the most interesting thing here was learning that keywords are symbols:

    (symbolp :foo) ; => t
    

    This was certainly a surprise the first time I saw it, although it does make sense. That prompted me to check how are keywords differentiated from symbols and I found the answer in the documentation of keywordp:

    keywordp is a built-in function in ‘C source code’.
    
    (keywordp OBJECT)
    
    Return t if OBJECT is a keyword.
    This means that it is a symbol with a print name beginning with ‘:’
    interned in the initial obarray.
    

    While I doubt that you’ll often (ever?) have to deal with keyword to symbol conversion I hope you’ve learned something fun and useful today! Keep hacking!

Subscribe via RSS | View Older Posts