Skip to content

Instantly share code, notes, and snippets.

(defun yf/forward-sexp-or-inside-next-sexp (&optional n) ""
(interactive "p")
(dotimes (_ n)
(condition-case nil
(forward-sexp)
(scan-error (save-match-data
(re-search-forward "\\s)*")
(when (looking-at "\\s(") (forward-char)))))))
(defun yf/narrow-to-window-view (printmsg)
(interactive "p")
(narrow-to-region (window-start)
(save-excursion
(goto-char (window-end nil t))
(when (not (pos-visible-in-window-p))
;; Line is not fully visible.
(forward-visible-line -1))
(point)))
(when printmsg
(lambda ()
(let ((hd (format-time-string "%Y")))
(goto-char (point-min))
(unless (derived-mode-p 'org-mode)
(error
"Target buffer \"%s\" for file+headline should be in Org mode"
(current-buffer)))
(if (re-search-forward
(format org-complex-heading-regexp-format (regexp-quote hd))
nil t)
;; -*- lexical-binding: t; -*-
(setq test-bar 'initial-value)
(defun test-test-bar ()
(message "testbar: %S" test-bar))
(let ((test-bar 'dynscope))
(test-test-bar)) ; => initial-value
(defvar test-bar 'newvalue "ignored")
(let ((test-bar 'dynscope))
(test-test-bar)) ; => dynscope
(let ((list
(mapcar
(lambda (proc)
(cons (format "%s" proc) proc))
(process-list))))
(cdr
(assoc (ido-completing-read "Process: "
(mapcar #'car list))
list)))
;;; rcirc-color.el -- color nicks
;; Copyright 2005-2013 Alex Schroeder
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of
;; the License, or (at your option) any later version.
;; This program is distributed in the hope that it will be
;; useful, but WITHOUT ANY WARRANTY; without even the implied
(add-hook 'shell-mode-hook #'delete-window-after-exit)
(defun delete-window-after-exit ()
(let ((proc (get-buffer-process (current-buffer))))
(add-function :after
(process-sentinel proc)
(lambda
(proc _change)
(let ((win (get-buffer-window (process-buffer proc))))
(when win
@YoungFrog
YoungFrog / attach.el
Created April 19, 2016 11:36 — forked from philjackson/attach.el
From an mu4e view, without prompt, save all attachments to a directory and open dired.
(defvar bulk-saved-attachments-dir (expand-file-name "~/Documents/mu4e"))
(defun cleanse-subject (sub)
(replace-regexp-in-string
"[^A-Z0-9]+"
"-"
(downcase sub)))
(defun view-attachments-dired (&optional msg)
"Saves all of the attachments in `msg' to a directory under
@YoungFrog
YoungFrog / after-init-emacs.el
Last active February 26, 2016 14:14
the docstring looks wrong (at least for MATCHER, possibly for the rest) and this does less things than the original perform-replace. Use at your own risk
(defun yf/perform-replace (matcher replacement &optional skip-predicate)
"Interactively replace MATCHER with REPLACEMENT
MATCHER is a regular expression or a function (see below).
REPLACEMENT is a text valid for `replace-match' or a function.
SKIP-PREDICATE, if given, is a function which will be called at every
match. If it returns nil, that occurrence is skipped silently."
(let (matched-string start end literal-replacement overlay)
(unwind-protect
(map-y-or-n-p
(lambda (_)

determine “current function” in the stack call

(defun cur-fun () (with-temp-buffer (let ((standard-output (current-buffer))) (backtrace)) (message (buffer-string)) (goto-char (point-min)) (dotimes (_ 3) (re-search-forward “^ [^(]” nil t))