Skip to content

Instantly share code, notes, and snippets.

@herbertjones
herbertjones / org-roam-search.el
Last active March 8, 2020 23:52
Org-roam search for backlinks
;;; -*- lexical-binding: t -*-
(defun org-roam-search ()
"Search for backlinks for a given article in a new buffer."
(interactive)
(let* ((source-org-roam-directory org-roam-directory)
(completions (org-roam--get-title-path-completions))
(title (completing-read "File: " completions))
(file-path (cdr (assoc title completions)))
(buf-name (format "*org-roam-search-%s*" title))
@herbertjones
herbertjones / org-roam-multi-dir.el
Last active February 20, 2020 15:44
Org-Roam multiple directories workaround hack
(defvar org-roam-directories nil
"Paths to org-roam files. List where CAR is name and CDR is path.")
;; Example:
;; (setq org-roam-directories '(("Home roam" . "~/Documents/home-roam")
;; ("Work roam" . "~/Documents/work-roam")))
;; Set first directory
(setq org-roam-directory (cdar org-roam-directories))
@herbertjones
herbertjones / bash-notes.org
Created February 1, 2019 04:45
Bash notes

Language Features

Variables and newlines

# Normal assignment doesn't work.
lines=$(printf "abc\n123\n\n"); echo -n "$lines" | wc -l
# 1  -- WRONG
empty=$(printf ""); echo -n "$empty" | wc -l
# 0  -- WRONG

# Problem is that variable assignment strips all newlines when assigning the
@herbertjones
herbertjones / with-new-window StumpWM macro.lisp
Last active August 23, 2018 02:04
with-new-window StumpWM macro
;; Non-macro macro helper
(defun run-and-act-on-new-window (cmd props timeout function)
"Run a command, setup a handler to apply a function to the new window once it's open."
(let* (focus-window-handler
timeout-handler
(timer (run-with-timer timeout nil
#'(lambda ()
;; Remove hooks after period of time should something go wrong.
(when focus-window-handler
(remove-hook *focus-window-hook* focus-window-handler))
@herbertjones
herbertjones / toggle-touchpad.sh
Created August 26, 2017 15:19
Toggle touchpad on laptop
#!/bin/bash
stderr() { cat <<< "$@" 1>&2; }
toggle_xinput_device()
{
declare -r -a device_filters=("$@")
if [[ ${#device_filters[*]} -eq 0 ]]; then
stderr "No filters provided."
@herbertjones
herbertjones / .spacemacs
Created March 2, 2015 05:49
.spacemacs
;; -*- mode: dotspacemacs -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration."
(setq-default
;; List of additional paths where to look for configuration layers.
;; Paths must have a trailing slash (ie. `~/.mycontribs/')
dotspacemacs-configuration-layer-path '("/home/herbert/spacemacs/my-layers/")
Loading /home/herbert/.emacs.d/contrib/git/config.el (source)...done
Loading /home/herbert/.emacs.d/spacemacs/packages.el (source)...done
Loading /home/herbert/spacemacs/my-layers/hfj-c++/packages.el (source)...done
Loading /home/herbert/spacemacs/my-layers/hfj-pastebins/packages.el (source)...done
Loading /home/herbert/.emacs.d/contrib/ace-window/packages.el (source)...done
Loading /home/herbert/.emacs.d/contrib/git/packages.el (source)...done
Loading /home/herbert/.emacs.d/contrib/perspectives/packages.el (source)...done
Loading /home/herbert/.emacs.d/spacemacs/extensions.el (source)...done
Loading /home/herbert/spacemacs/my-layers/hfj-c++/extensions.el (source)...done
Loading /home/herbert/spacemacs/my-layers/hfj-pastebins/extensions.el (source)...done
@herbertjones
herbertjones / config.el
Created February 27, 2015 16:36
Instructions for a personal snippets layer
;; Place this in layer directory and create a "snippets" directory
;; in the same layer directory as this file to have a personal
;; layer snippets repository
;; My snippets directory
(setq hfj-snippets/snippet-dir
(concat (file-name-directory load-file-name) "snippets"))
(setq yas-snippet-dirs
(list hfj-snippets/snippet-dir))
@herbertjones
herbertjones / gist:6fb319c8a257658f93cb
Created February 27, 2015 16:30
open file at cursor
;; Stolen from http://xahlee.blogspot.com/2013/05/emacs-open-file-path-under-cursor-fast.html
(defun hfj/open-file-at-cursor ()
"Open the file path under cursor.
If there is text selection, uses the text selection for path.
If the path is starts with “http://”, open the URL in browser.
Input path can be {relative, full path, URL}.
This command is similar to `find-file-at-point' but without prompting for confirmation.
"
(interactive)
(let ( (path (thing-at-point 'filename)))
@herbertjones
herbertjones / gist:94e3e1dd271831d5ea61
Created February 24, 2015 12:44
Navagation mode idea
(evil-leader/set-key
"jn" 'spacemacs/navagation-micro-state)
(defun spacemacs//navagation-mode-ms-full-doc ()
"Full documentation for helm navigation micro-state."
"
[?] display this help
[)] [0] forwards sentence
[)] [9] backwards sentence
[}] [{] forwards/backwards paragraph