Fix non-display of ivy-rich switch buffer directories in Emacs

Recently, as I replaced more of my Emacs-helm configuration with counsel and ivy, I noticed that ivy-switch-buffer, when augmented by ivy-rich, was not showing the directories of the buffers it was listing.

After some Lisp spelunking, I discovered that it was because ivy-rich relies on the presence of either the projectile package, something I do not wish to have in my Emacs configuration, or on project.el, which I also do not use.

In this post, I show how you can get full buffer filenames and project names with the lighter-than-projectile and more-robust-than-project.el find-file-in-project, or how you can bypass the project name functionality completely and just get buffer filenames with no extra packages.

Sort TypeScript import groups from standard to local

Welcome to the first entry in a new series that’s probably going to stop with this first entry, or maybe not.

The series is called Charl’s Unwritten Rules of Software Development, or cursd.

I am also planning another series called Charl’s Unwritten Rules of Applied Machine Learning that is on its part probably going to remain in the planning stage, or maybe not.

In this first CURSD post, I would like to document my hitherto unwritten rule for ordering your TypeScript (or JavaScript) import groups.

An Emacs Lisp function to convert attachment: links to file: links for ox-hugo exports

You might have noticed the side-note in yesterday’s blog post where I mentioned that exporting Orgmode notes with org-download attachment-style screenshots to blog posts using ox-hugo required one to convert [[attachment:...]]-style links to [[file:...][file:...]]-style links.

Because the barrier from private note to possibly useful blog post should be as low as possible, I made the below function that will do the required conversion for the link under your cursor.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
(defun cpb/convert-attachment-to-file ()
  "Convert [[attachment:..]] to [[file:..][file:..]]"
  (interactive)
  (let ((elem (org-element-context)))
    (if (eq (car elem) 'link)
        (let ((type (org-element-property :type elem)))
          ;; only translate attachment type links
          (when (string= type "attachment")
            ;; translate attachment path to relative filename using org-attach API
            ;; 2020-11-15: org-attach-export-link was removed, so had to rewrite
            (let* ((link-end (org-element-property :end elem))
                   (link-begin (org-element-property :begin elem))
                   ;; :path is everything after attachment:
                   (file (org-element-property :path elem))
                   ;; expand that to the full filename
                   (fullpath (org-attach-expand file))
                   ;; then make it relative to the directory of this org file
                   (current-dir (file-name-directory (or default-directory
                                                         buffer-file-name)))
                   (relpath (file-relative-name fullpath current-dir)))
              ;; delete the existing link
              (delete-region link-begin link-end)
              ;; replace with file: link and file: description
              (insert (format "[[file:%s][file:%s]]" relpath relpath))))))))

This Stack Overflow answer gave me a great basis using the org-element API.

Set severity override of Visual Studio Code Pylance type mismatches for better visual distinction

Pylance is Microsoft’s new and improved Python language server.

I have been using this in my Visual Studio Code remote editing sessions (editing Python codes on the machine learning Linux machine next to me, from my laptop), and I’m enjoying its new type-checking capabilities.

Today I discovered a little configuration change that improved my Pylance experience, so I thought I’d share in case it helps anyone else.

Aside: ox-hugo exports with org-download screenshots

It was also an excuse to test how ox-hugo exports would work for a note straight from my daily journal if screenshots were involved.

Open WSL2 files in Windows apps using Emacs TRAMP

From the department of how-obscure-can-you-get-really, I present you with this neat trick to open WSL2 files in their native Windows handlers via Emacs TRAMP connection from WSL1 to WSL2.

Motivation

My use case is this:

  • On Windows, I use Emacs primarily from WSL1 to manage everything on Windows, on WSL1 and on the WSL2 distros I use for development.
  • I’m often connected to WSL2 via TRAMP, for managing files with dired, manipulating the results of simulations, and using the amazing magit.
  • When I open e.g. a simulation report in HTML or some other format, I would ideally like it to open with my Windows browser.

Method

The code below is a slightly modified version of crux-open-with from the crux package, with the one major change that it uses the relevant TRAMP mechanisms to spawn a remote process to open the file.

Emacs, WSL, helm-locate and Everything

On Windows, running Emacs on WSL (the Windows Subsystem for Linux, or rather Linux in Windows), is faster and in my experience an altogether a better experience than running native Windows Emacs.

However, you will need to do some tweaking to use it to its maximum potential, some of which I have written about before.

In this post, I show a small but useful trick to use the brilliant and lightning fast Everything search tool to find directories and files anywhere on your Windows system whilst using helm-locate from your WSL Emacs.

Voice capture org-mode notes and more using Siri Shortcuts on iOS

This post originally appeared at Org Mode Exocortex, my Org mode-focused blog, on April 30, 2020.

:ID: b3c6cee0-567e-4324-9685-f6fd9959d402

Introduction

Inspired by Stéfan’s post explaining how to voice capture TODOs using Google Assistant on Android, I decided to find out how one would go about hooking up Siri dictation on iOS to Org mode.

It turns out that Siri Shortcuts is a pretty amazing tool that can be used for all kinds of automation on your iPhone or iPad.