;;; jakob.el -*- lexical-binding: t; -*- ;;; ;;; Author: Jakob L. Kreuze ;;; URL: https://git.sr.ht/~jakob/.emacs.d/ ;;; ;;; Custom elisp written by yours truly that is independent of any particular ;;; package. ;;; ;;; ;;; Configuration. ;;; ;; Bind some keys for working with this configuration file. (defun config-goto () "Switch to a buffer visiting the config file." (interactive) (find-file "~/.emacs.d/init.el")) (bind-key "C-c e" #'config-goto) ;;; ;;; pass ;;; ;; Here's a snippet for interactively pulling a password from password-store, so ;; I'm not spawning a terminal every time I need to invoke my password manager. (defvar password-store-directory "~/.password-store" "Directory containing passwords managed by `pass'.") (defun pass-password-files () "Returns the paths of every password managed by `pass'." (let ((prefix-length (1+ (length password-store-directory))) (suffix-length (length ".gpg"))) (mapcar #'(lambda (path) (cl-subseq path prefix-length (- suffix-length))) (directory-files-recursively password-store-directory ".gpg$")))) (defun pass () "Prompt for a password and copy it to the clipboard. Passwords are taken from `password-store-directory'." (interactive) (let* ((account (completing-read "Account: " (pass-password-files))) (path (concat password-store-directory "/" account ".gpg"))) (with-temp-buffer (insert-file-contents path) (clipboard-kill-ring-save 1 (line-end-position))) (message "Password for %s copied to clipboard." account))) ;;; ;;; 8-ball ;;; ;; A little snippet for getting an answer to a dumb question. Responses were ;; lifted from Wikipedia's page [1] about the toy. ;; ;; This really only exists for experimenting with `native-comp'. ;; ;; [1]: https://en.wikipedia.org/wiki/Magic_8-Ball (defun consult () "Consult the magic 8-ball. Interactive function to consult the magic 8-ball for answers to very important questions." (interactive) (let ((responses (list "It is certain." "It is decidedly so." "Without a doubt." "Yes - definitely." "You may rely on it." "As I see it, yes." "Most likely." "Outlook good." "Yes." "Signs point to yes." "Reply hazy, try again." "Ask again later." "Better not tell you now." "Cannot predict now." "Concentrate and ask again." "Don't count on it." "My reply is no." "My sources say no." "Outlook not so good." "Very doubtful."))) (message (elt responses (mod (random) (length responses)))))) ;;; ;;; Editing Commands ;;; (defun expand-region () "Turn space-delimited line of sexps into several lines." (interactive) (save-excursion (let* ((begin (region-beginning)) (end (region-end))) (goto-char begin) (while (<= (point) end) (forward-sexp) (newline) (indent-for-tab-command))))) (defun flatten-region () "Turn newline-delimited region of sexps into single line." (interactive) (save-excursion (let* ((begin (region-beginning)) (end (region-end))) (goto-char end) (while (> (point) begin) (forward-sexp -1) (delete-char -1) (insert ? ))))) (defun stringify-region () "Wrap all sexps in region with double quotes." (interactive) (save-excursion (let* ((begin (region-beginning)) (end (region-end))) (goto-char begin) (while (< (point) end) (forward-sexp) (forward-sexp -1) (insert ?\") (forward-sexp) (insert ?\") (setf end (+ 2 end))))))