Emacs, scripting and anything text oriented.
Kaushal Modi

Posts in β€˜posts’


  • Golang Quirk: Number-strings starting with "0" are Octals

    Someone in the Golang team thought that it would be a good idea to consider all numbers (represented as strings) starting with “0” as Octals.. so “010” is actually 8.. Really?

  • Optimize your FontAwesome

    How to trim the FontAwesome JS for your website, using Emacs Lisp.

  • Fragmentions

  • Git diff Minified JS and CSS

    Make the git diff output be more useful when diffing minified .js and .css files.

  • Hugo: Leaf and Branch Bundles

    Content organization for Hugo posts/articles using Page Bundles.

  • Org Contribution Flow-chart

    A handy flow-chart if you are confused about when commits happen to Org maint branch vs master branch, what ends up in the Elpa version of Org, and so on.

  • Field Formatters in Org table

    Using field-formatters to format results of Org table formulae.

  • Your car will be ready in 8000 seconds

        Huh? πŸ˜•

    Well, a mechanic usually wouldn’t give you a time estimate in seconds, but a tool I am using prints something like this at the end:

    The simulation took 54227.9 seconds in CPU time.

    That triggered me to write a “little” script to convert seconds to human time i.e. time in days, hours, minutes and seconds.

  • LaTeX in HTML

    Ever wondered how to show LaTeX in HTML or a Hugo blog post exported from Org?

  • Converting Org keywords to lower-case

    I never quite liked the trend to have upper-cased keywords in Org documents, like #+TITLE.

    So it was a pleasure to see that trend start changing in this Org commit.. so that that same keyword would now be written as #+title.


  • Narrowing the Author column in Magit

    The Org and Worg git repos can be committed to only via ssh protocol (and not https), and for technical reasons, I cannot commit to those repos via ssh from my primary development machine. So I ended up with a flow that involves pushing commits to those repos using my Nexus 6p phone.

    Magit is how I git, and I love to primarily work from the ∗magit-log∗ buffer (M-x magit-status, l b). But the default column widths were not optimal on a Nexus 6p 5.7" screen. And that’s what inspired this tweak, which looks great on a regular desktop monitor too.

  • Building Org Development version

    <2018-02-20 Tue>
    Refactor the code using more canonical methods.
    <2018-01-03 Wed>
    Update the Org repo links as per the announcement on Org mailing list on <2017-12-28 Thu>.

    I am assuming that you already know what Org or org-mode is and that’s why you are here.

    You would want to build Org from its development branch (master branch) to get the latest and greatest goodies plus bug fixes! Go through the ORG-NEWS file to read about the new features.

    If you like what you see there, here are the steps for installing the development version of Org.

  • A Better less

    I use emacs – with a server1 and client setup – so that I can quickly open new files in it using emacsclient. My typical setup is to have xterm + tmux on one monitor and a single emacs(client) frame on another. But there are times when I do not want to shift focus from one monitor to another, like when I just need to review some log file. So I started using an alias to emacs -nw -Q to quickly open log files, review, filter, and C-x C-c.

    Of course, that’s not where this post ends. An alias was no longer adequate to do what I wanted it to do more ..

  • Installing bleeding edge Hugo + Goorgeous

    Update (2017/06/16)

    Updated the github source references as per the changes in hugo v0.231. Also made the shell script ShellCheck-passing! πŸ™Œ Β§

    You already got go installed, and that’s why are you reading it.

             If not – Go! Install it!

    So.. now that you have go installed, why settle for the release version of hugo! You are reading this blog post generated using the bleeding edge of hugo2.

    In addition, Hugo v0.19 onwards supports the org-mode syntax3, which is so much more awesome than markdown, especially if you are using emacs.

    This post is about how you can install the latest versions of hugo and the go package that adds the org-mode support – goorgeous.

  • Installing go toolchain

    There are 2 reasons why I suggest installing go to anymore, whether they are Go developers, or not (like me).

    1. You can then build amazing utilities like peco, hugo and noti.
    2. It’s easy!

  • Stuff about command-line ftp

    To connect to a machine with ip MACHINE, you simply need to enter the below at command-line:

    ftp MACHINE

    See below for a list of commands you would typically use once you ftp to a machine.

  • Installing rust toolchain

    Lately, I have come to know of a command line search utility called ripgrep, coded in rust, that is capable of faster code searches (at least for my use cases) than grep or ag. So I got interested in building the latest versions of rg (ripgrep binary name) directly from its github master branch rather than waiting for its release binaries.

    So came the need to install the rust toolchain on my machine. Luckily, installing that was super easy; here are the steps:

  • Count Down Timer in Shell

    I was working on a tcsh script that did some cool stuff. But if a user ran that script not knowing the true impact of the script, it could make some bad irreversible changes.

    While I could simply echo a warning statement and put a sleep 10, I wanted the wait time to be shown live.


  • Optimize your .git

    I was reviewing what was occupying the maximum disk space using the ncdu command line utility. One of the top candidates was the git clone of org-mode. It was using 2.4GB of my disk space!

    Surprised by that, I started looking around1 if there was a way to optimize the cloned git repositories i.e. the .git/ directories. And sure enough, there was a way.

  • Check If a Command Exists from Shell Script

    I often need to check if a particular executable is present in the PATH before I can proceed with what I am doing in a shell script. Also I need to work with both tcsh and bash scripts. Below presents the different solutions that have worked for these shell scripts for me.

  • Second Argument to basename

    It is quite common knowledge that the basename command is used to get just the file name without its full path.

    > basename /home/$USER/file.txt

    But what wasn’t common knowledge, at least to me, was that basename also accepts a second argument ..

  • Emacsclient on Windows

    Using emacsclient instead of the emacs binary is a very useful technique to prevent loading emacs from scratch each time you open a new file. That technique is useful on Windows too. But for this to work on Windows, we need some more elisp and Windows environment variable configuration than just the below code,

    (require 'server)
    ;; Start a server if (server-running-p) does not return t (e.g. if it
    ;; returns nil or :other)
    (or (eq (server-running-p) t)

  • Generating a transparent favicon

    While generating a simple favicon for this blog, I went through a little exercise on how to generate a favicon with transparent background. I did not want the favicon with square block background which runs a risk of not blending well with the browser tab background as seen below:

    Bad Favicon

  • How I Created this Blog

    I have been toying with the idea to use hugo as my static web site generator for few weeks now. And then the news of its version 0.17 release are announced, and hugo shows up on Hacker News once again.


  • Do Ediff as I mean

    <2017-09-19 Tue>
    Updated modi/ediff-dwim to the latest revision in my config.

    In almost all of my ediff use cases, I would have windows open side-by-side in a frame, and then I would want to do a diff between the two using ediff-buffers.

    But emacs doesn’t know that I obviously want to diff those two side-by-side buffers! So it always asks me to select the buffers to be diffed. The same problem is when using ediff-files too.

    So I came up with the following helper function to pick the correct ediff command.

  • Elisp Meta Characters in String

    The setup of outshine package for emacs requires the user to set the variable outline-minor-mode-prefix to "\M-#" before the outline-mode package (that ships with emacs) is loaded.

    The best way to do this is via the Customize interface in emacs.

    So I did M-x customize and set that variable’s value to "\M-#" and restarted emacs and that worked.

    But then I was surprised to see that value being saved in the custom.el as '(outline-minor-mode-prefix "\243").


  • How to undo the unpushed commits in magit?

    In Magit buffer *magit: ..*,

    • Hit x
    • Select origin/master

  • tmux Shift + Mouse

    Using mouse to copy/paste in tmux panes.

  • Save a macro as a function in emacs

    I am in the process of converting traditional verilog test benches to SystemVerilog UVM test benches. As per the UVM methodology, it is recommended to use `uvm_info instead of $display statements so that the info statement encodes a Message ID and Message Verbosity along with the message required to be printed.

    I won’t go in more detail about UVM and verilog as this post is about how I can save a macro that I use very frequently into an elisp function.

  • Org-to-HTML and fill-column-indicator

    Lately I was having an issue in the org to html conversion where the newline characters got appended with funky unicode characters.

    Full detail is in this reddit post I started.

  • Getting started with texlive

    A list of my frequently used texlive manager commands.

  • Formatting in LaTeX

    Notes and references for formatting in LaTeX.

  • Inline LaTeX code fragments in Org

    At times you might need your org exported pdf to have the exact font rendering as generated by a snippet of LaTeX code. To do that, wrap that code inbetween the \( and \) delimiters.

  • How to quickly create a table in org mode

    Set the buffer major mode to org-mode. If the file extension is a .org, that major mode would be set automatically by emacs.

    Follow the below steps to create a table ..

  • Returning a matched group in Matlab

    In Matlab, the groups that are defined in parentheses are saved as tokens.

    Here is a example where I am retreiving the first matched group or token.

  • zsh Guide by Peter Stephenson

  • Search/replace groups using sed

    This is the most common way of my sed usage:

    echo Good morning | sed 's/\(.*\s\+\).*/\1evening/g'

    Here are brief notes on that ..

  • Installing custom fonts in Linux

    I’ll step through how to set custom fonts for xterm terminal. My default shell is tcsh.

  • Assigning a hash to another hash

    A hash can be assigned to a key of another hash using hash reference.

  • How to remove duplicate lines using awk?

    If you type echo "Hi\nHow\nHi\nAre\nHi\nYou?\nAre", you will get this in your terminal:


    Here’s how we can remove the duplicate lines using awk ..

  • One liner if-else in awk

    Tiny snippets showing if/else use in awk ..

  • Using sed

    sed stands for stream editor.

    This is the most common way of my sed usage:

    echo [SOMETHING] | sed 's/old/NEW/g'

  • Binary <> Decimal <> Hex conversion in Python

    Python snippets to do number representation conversion among binary/decimal/hexadecimal.

  • How to change upper case to lower via search/replace?

    This posts explain how the emacs in-built query-replace-regexp command can be used to convert upper-cased strings to lower case.

  • How to save a function name in a variable in elisp?

    I have a couple of theme packages installed on my emacs but I would like to assign a default theme.

    I set the zenburn theme via a function zenburn. I set the leuven theme via another function leuven. But in my emacs startup I didn’t want to hard-code either of these function and thus arose the need to set a variable to one of these functions.

  • Writing aliases with optional arguments in tcsh

    Some times I would need to define an alias in tcsh which can have optional arguments. tcsh doesn’t seem to support that directly.

    Here’s how I solve that problem.

  • ctags, systemverilog and emacs

    Update (2017/02/23) — Now I use GNU Global with Universal Ctags as back-end to generate the tag files. In emacs, I use the ggtags package – [config].

    This post still has value if you are interesting in configuring ctags only.

    This posts shows how to set up ctags to parse SystemVerilog code and how to access that tag database in emacs.

  • Escaping dollar signs in tcsh

    I found how to escape a $ sign in a regex expression in a tcsh alias. BUT it is UGLY!

  • How to add footnotes in Octopress posts?

    Update (2017/02/23) — Now I use Hugo instead of Octopress for blogging. But the same method of using [^1] works for creating footnotes.

    While looking for a way to add footnotes to my posts, I came across this post.

    Based on that, here is how I got the footnotes working:

  • Send a command to every pane/window/session in tmux

    Faster way to send the same command to each and every pane in your tmux session.

  • How to do math in Makefile?

    If you have bc installed, you can use it to do math operations on variables in a Makefile.

  • Get current directory name without path

    This post shows how to get the current directory name without the preceeding path, using awk or rev+cut or the boring basename.

  • First Post

    Update: This first post was created using octopress, but now I am using hugo.

    Testing the first post using octopress.