Skip to content

Instantly share code, notes, and snippets.

(defun term-git-mode--get-branch ()
(let ((branches (vc-call-backend 'git 'branches)))
(when branches (car branches))))
(define-minor-mode term-git-mode
"show current branch in modeline in terminal-modes"
:lighter (:eval (let ((git-branch (term-git-mode--get-branch)))
(if git-branch
(format " git:%s" git-branch)
""))))
@knollet
knollet / .emacs
Last active May 15, 2023 08:31
Snippet to have paste in (ansi-)term-mode with C-c C-y
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ansi-term
(add-hook 'term-exec-hook
(lambda ()
(define-key term-raw-map (kbd "C-c C-y") 'term-paste)
(define-key term-raw-map (kbd "C-c y") 'term-paste)))
@knollet
knollet / my-trash-cli.sh
Last active September 1, 2023 10:11
source my-trash-cli.sh
function trash {
TRASHDIR="$HOME/TRASH"
DATE="$(date '+%Y-%m-%d_%H:%M:%S.%N')"
if [ -z "$1" ]; then
echo "usage: $0 <filenames...>" > /dev/stderr
exit 1
fi
for FILE in "$@"; do

Emacs with 24 bits color in terminal

Troubleshooting

Recompile terminfo

Once the colors just stopped working, recompiling terminfo (see tic) worked for me. Perhaps there was an system wide update of terminfo and the format was changed somehow, so the old compiled files

(defun buffer-minus (subtrahend)
"This function takes the name of a buffer,
and removes every line in the current buffer present in the given one.
The lines are removed with `delete-matching-lines' which uses the given string as a regex
but it is good enough..."
(interactive "*b")
(let ((sub-list
(with-current-buffer subtrahend
(string-split (buffer-string) "\n" t "[\t ]+"))))
(defun mo-paging--what-page ()
"Print page and line number of point."
(interactive)
(save-restriction
(widen)
(save-excursion
(let ((count 1)
(opoint (point)))
(goto-char (point-min))
(while (re-search-forward page-delimiter opoint t)
@knollet
knollet / tmacs-emacs.el
Last active November 17, 2023 10:39
start an ansi-term with a reasonable name
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; tmacs
(defvar tmacs--counter 0)
(defun tmacs--find-free-number ()
(cl-do ((num 0 (+ 1 num)))
((not (get-buffer (format "*tmacs<%s>*" num)))
num)))
(defun tmacs ()
(interactive)
@knollet
knollet / insert-pair.el
Created November 16, 2023 17:04
surround.el
;;;;; insert pair -- "Surround"
(global-set-key (kbd "<f12> s \"") 'insert-pair)
(global-set-key (kbd "<f12> s '") 'insert-pair)
(global-set-key (kbd "<f12> s (") 'insert-pair)
(global-set-key (kbd "<f12> s [") 'insert-pair)
(global-set-key (kbd "<f12> s {") 'insert-pair)
(global-set-key (kbd "<f12> s <") 'insert-pair)
@knollet
knollet / trash.sh
Created March 15, 2024 14:58
Trash on the shell. Small bashrc implementation
function trash {
TRASHDIR="$HOME/TRASH"
DATE="$(date '+%Y-%m-%d_%H:%M:%S.%N')"
if [ -z "$1" ]; then
echo "usage: $0 <filenames...>" > /dev/stderr
exit 1
fi
for FILE in "$@"; do