From 78e80e056452b736903775efc5947e2f416b87c0 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Wed, 6 May 2015 23:00:05 -0400 Subject: Change prefix argument for scratch file commands --- lisp/init-files.el | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) (limited to 'lisp') diff --git a/lisp/init-files.el b/lisp/init-files.el index bf65f5e..ecd6bdc 100644 --- a/lisp/init-files.el +++ b/lisp/init-files.el @@ -135,36 +135,30 @@ entering `ch' is equivalent to `*.[ch]'.") Format of each element should be (CHARACTER EXTENSION DOC). DOC is not required.") -(defun km/scratch-find-file (erase) +(defun km/scratch-find-file (&optional pwd) "Find scratch buffer. Prompt with characters from `km/find-scratch-buffers' to determine the extension of the scratch file. -With prefix argument ERASE, delete contents of buffer." +With prefix argument PWD, find the scratch file in +`default-directory' instead of /tmp." (interactive "P") - (switch-to-buffer (km/scratch--find-file-no-select erase))) + (switch-to-buffer (km/scratch--find-file-no-select pwd))) -(defun km/scratch-find-file-other-window (erase) +(defun km/scratch-find-file-other-window (&optional pwd) "Like `km/find-scratch-file', but open buffer in another window." (interactive "P") - (switch-to-buffer-other-window (km/scratch--find-file-no-select erase))) - -(defun km/scratch--find-file-no-select (erase) - (let ((scratch-buffer - (find-file-noselect (km/scratch--get-file-name)))) - (when erase - (with-current-buffer scratch-buffer - (erase-buffer))) - scratch-buffer)) - -;; This is based off of Projectile's commander. -(defun km/scratch--get-file-name () - (-let* ((choices (-map #'car km/find-scratch-buffers)) - (prompt (concat "Scratch buffer [" choices "]: ")) - (ch (read-char-choice prompt choices)) - ((_ ext _) (assq ch km/find-scratch-buffers))) - (concat "/tmp/scratch" ext))) + (switch-to-buffer-other-window (km/scratch--find-file-no-select pwd))) + +(defun km/scratch--find-file-no-select (pwd) + (find-file-noselect (km/scratch--get-file-name pwd))) + +(defun km/scratch--get-file-name (pwd) + (let* ((choices (mapcar #'car km/find-scratch-buffers)) + (ch (read-char-choice (concat "[" choices "]") choices)) + (ext (cadr (assq ch km/find-scratch-buffers)))) + (concat (if pwd default-directory "/tmp/") "scratch" ext))) (global-set-key (kbd "C-c s") 'km/scratch-find-file) (define-key ctl-x-4-map "s" 'km/scratch-find-file-other-window) -- cgit v1.2.3