Skip to content

Instantly share code, notes, and snippets.

@nxtr
nxtr / custom-set-variable.el
Created July 25, 2023 13:48
Update saved value of custom variable
(defmacro custom-set-variable (variable)
"Update saved value of custom `VARIABLE'"
`(custom-set-variables
'(,variable `,,variable 'now nil ,(format "Customized in %s" load-file-name))))
@nxtr
nxtr / counsel-yank-pop.el
Created March 11, 2021 10:37
Advice counsel-yank-pop for proper vterm-mode yank-pop using emacs-libvterm, ivy and counsel
(define-advice counsel-yank-pop (:around (fun &rest args))
(if (equal major-mode 'vterm-mode)
(let ((counsel-yank-pop-action-fun (symbol-function
'counsel-yank-pop-action))
(last-command-yank-p (eq last-command 'yank)))
(cl-letf (((symbol-function 'counsel-yank-pop-action)
(lambda (s)
(let ((inhibit-read-only t)
(last-command (if (memq last-command
'(counsel-yank-pop
@nxtr
nxtr / .sommelierrc
Created January 10, 2021 12:56
Chrome OS, Crostini, Sommelier: Import environment from ~/.bash_profile and ~/.profile
# Copyright 2020 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Use this file to customize per-user sommelier options.
#
# For documentation, see:
# https://chromium.googlesource.com/chromiumos/platform2/+/HEAD/vm_tools/sommelier/
# Import environment from ~/.bash_profile and ~/.profile
@nxtr
nxtr / nxtr-ivy-posframe--display.el
Last active January 29, 2021 08:53
ivy-posframe: Advice for default font from selected frame
(define-advice ivy-posframe--display (:around (fun &rest args))
(let ((ivy-posframe-font (face-attribute 'default :font (selected-frame))))
(apply fun args)))
@nxtr
nxtr / ivy-posframe-get-size.el
Last active January 29, 2021 18:19
A dynamic and adaptive function used by `ivy-posframe-size-function'
(ivy-posframe-size-function
(lambda ()
(list
:height (or ivy-posframe-height ivy-height)
:width ivy-posframe-width
:min-height (or ivy-posframe-min-height ivy-height)
:min-width (or ivy-posframe-min-width
(let* ((buf-rows (split-string
(with-current-buffer ivy-posframe-buffer
(buffer-string))
@nxtr
nxtr / expand-file-name-current-directory.el
Created December 9, 2018 23:51
Convert filename NAME to absolute and canonicalize, starting with directory of `load-file-name' or `buffer-file-name' or `default-directory' if NAME is relative (does not startwith slash or tilde).
(eval-and-compile
(unless (fboundp 'expand-file-name-current-directory)
(defun expand-file-name-current-directory (name)
"Convert filename NAME to absolute and canonicalize.
Starting with directory of `load-file-name' or `buffer-file-name' or
`default-directory' if NAME is relative (does not startwith slash or tilde)."
(let ((dir (file-name-directory (or load-file-name buffer-file-name ""))))
(expand-file-name name dir)))))
@nxtr
nxtr / files.el
Created September 3, 2018 18:28
Convert filename NAME to absolute and canonicalize, starting with directory of `load-file-name' or `buffer-file-name' or `default-directory' if NAME is relative (does not start with slash or tilde).
(defun expand-file-name-current-directory (name)
"Convert filename NAME to absolute and canonicalize, starting with directory
of `load-file-name' or `buffer-file-name' or `default-directory' if NAME
is relative (does not start with slash or tilde)."
(let ((dir (file-name-directory (or load-file-name buffer-file-name ""))))
(expand-file-name name dir)))))
@nxtr
nxtr / ert.el
Created August 25, 2018 09:42
EVM_EMACS=emacs-24.3-travis,Test all-completions condition: (invalid-function (a b)), Test all-completions backtrace: (a b)("" nil t) all-completions("" (a b) nil)
(ert-deftest all-completions ()
(should
(equal '("a" "b") (all-completions "" '(a b) nil))))
@nxtr
nxtr / key-bindings.el
Created August 20, 2018 15:51
Key binding of a lambda function as a uninterned symbol,
(define-key ivy-mode-map (kbd "C-s")
(defalias (make-symbol "swiper-or-swiper-all")
;; Wrapped in `defalias' with uninterned SYMBOL so `describe-key'
;; displays command as a proper symbol instead of byte-codes
(lambda ()
"Runs the command swiper.
With a prefix argument, run the command swiper-all."
(interactive)
(if current-prefix-arg
(swiper-all)
@nxtr
nxtr / subr.el
Created August 16, 2018 15:02
with-file-temp-buffer: (FILENAME &rest BODY)
(defmacro with-file-temp-buffer (filename &rest body)
"Create a temporary buffer visiting FILENAME, and evaluate BODY there like
`progn'."
(declare (indent 1) (debug t))
(let* ((temp-buffer (make-symbol "temp-buffer")))
`(let* ((truename (abbreviate-file-name (file-truename ,filename)))
(number (nthcdr 10 (file-attributes truename)))
(,temp-buffer (find-file-noselect-1
(create-file-buffer ,filename)
,filename 'nowarn nil truename number)))