summaryrefslogtreecommitdiff
path: root/modules/custom-file-buffer.el
diff options
context:
space:
mode:
Diffstat (limited to 'modules/custom-file-buffer.el')
-rw-r--r--modules/custom-file-buffer.el141
1 files changed, 74 insertions, 67 deletions
diff --git a/modules/custom-file-buffer.el b/modules/custom-file-buffer.el
index 1a3a0d68..e722f734 100644
--- a/modules/custom-file-buffer.el
+++ b/modules/custom-file-buffer.el
@@ -38,23 +38,23 @@ Set to \\='auto to auto-detect once per session.")
(cond
;; User-specified command
((and (stringp cj/print-spooler-command)
- (> (length cj/print-spooler-command) 0))
- (or (executable-find cj/print-spooler-command)
- (user-error "Cannot print: spooler command '%s' not found in PATH"
- cj/print-spooler-command))
- cj/print-spooler-command)
+ (> (length cj/print-spooler-command) 0))
+ (or (executable-find cj/print-spooler-command)
+ (user-error "Cannot print: spooler command '%s' not found in PATH"
+ cj/print-spooler-command))
+ cj/print-spooler-command)
;; Auto-detect once per session
((eq cj/print-spooler-command 'auto)
- (or cj/print--spooler-cache
- (let ((cmd (or (and (executable-find "lpr") "lpr")
- (and (executable-find "lp") "lp"))))
- (unless cmd
- (user-error "Cannot print: neither 'lpr' nor 'lp' found in PATH"))
- (setq cj/print--spooler-cache cmd)
- cmd)))
+ (or cj/print--spooler-cache
+ (let ((cmd (or (and (executable-find "lpr") "lpr")
+ (and (executable-find "lp") "lp"))))
+ (unless cmd
+ (user-error "Cannot print: neither 'lpr' nor 'lp' found in PATH"))
+ (setq cj/print--spooler-cache cmd)
+ cmd)))
(t
- (user-error "Invalid value for cj/print-spooler-command: %S"
- cj/print-spooler-command))))
+ (user-error "Invalid value for cj/print-spooler-command: %S"
+ cj/print-spooler-command))))
;;;###autoload
(defun cj/print-buffer-ps (&optional color)
@@ -63,23 +63,23 @@ With prefix argument COLOR, print in color; otherwise print in monochrome.
Sends directly to the system spooler with no header."
(interactive "P")
(unless (require 'ps-print nil t)
- (user-error "Cannot print: ps-print library not found"))
+ (user-error "Cannot print: ps-print library not found"))
(let* ((spooler (cj/print--resolve-spooler))
- (want-color (not (null color)))
- (have-region (use-region-p)))
- (let ((ps-lpr-command spooler)
- (ps-printer-name nil) ; default system printer
- (ps-lpr-switches nil)
- (ps-print-color-p want-color)
- (ps-use-face-background want-color)
- (ps-print-header nil)) ; no headers
- (if have-region
- (ps-print-region-with-faces (region-beginning) (region-end))
- (ps-print-buffer-with-faces)))
- (message "Sent %s to default printer via %s (%s)"
- (if have-region "region" "buffer")
- spooler
- (if want-color "color" "monochrome"))))
+ (want-color (not (null color)))
+ (have-region (use-region-p)))
+ (let ((ps-lpr-command spooler)
+ (ps-printer-name nil) ; default system printer
+ (ps-lpr-switches nil)
+ (ps-print-color-p want-color)
+ (ps-use-face-background want-color)
+ (ps-print-header nil)) ; no headers
+ (if have-region
+ (ps-print-region-with-faces (region-beginning) (region-end))
+ (ps-print-buffer-with-faces)))
+ (message "Sent %s to default printer via %s (%s)"
+ (if have-region "region" "buffer")
+ spooler
+ (if want-color "color" "monochrome"))))
;; ------------------------- Buffer And File Operations ------------------------
@@ -87,63 +87,63 @@ Sends directly to the system spooler with no header."
"Move both current buffer and the file it visits to DIR."
(interactive "DMove buffer and file (to new directory): ")
(let* ((name (buffer-name))
- (filename (buffer-file-name))
- (dir
- (if (string-match dir "\\(?:/\\|\\\\)$")
- (substring dir 0 -1) dir))
- (newname (concat dir "/" name)))
- (if (not filename)
- (message "Buffer '%s' is not visiting a file!" name)
- (progn (copy-file filename newname 1) (delete-file filename)
- (set-visited-file-name newname) (set-buffer-modified-p nil) t))))
+ (filename (buffer-file-name))
+ (dir
+ (if (string-match dir "\\(?:/\\|\\\\)$")
+ (substring dir 0 -1) dir))
+ (newname (concat dir "/" name)))
+ (if (not filename)
+ (message "Buffer '%s' is not visiting a file!" name)
+ (progn (copy-file filename newname 1) (delete-file filename)
+ (set-visited-file-name newname) (set-buffer-modified-p nil) t))))
(defun cj/rename-buffer-and-file (new-name)
"Rename both current buffer and the file it visits to NEW-NAME."
(interactive
(list (if (not (buffer-file-name))
- (user-error "Buffer '%s' is not visiting a file!" (buffer-name))
- (read-string "Rename buffer and file (to new name): "
- (file-name-nondirectory (buffer-file-name))))))
+ (user-error "Buffer '%s' is not visiting a file!" (buffer-name))
+ (read-string "Rename buffer and file (to new name): "
+ (file-name-nondirectory (buffer-file-name))))))
(let ((filename (buffer-file-name)))
- (if (get-buffer new-name)
- (message "A buffer named '%s' already exists!" new-name)
- (progn
- (rename-file filename new-name 1)
- (rename-buffer new-name)
- (set-visited-file-name new-name)
- (set-buffer-modified-p nil)))))
+ (if (get-buffer new-name)
+ (message "A buffer named '%s' already exists!" new-name)
+ (progn
+ (rename-file filename new-name 1)
+ (rename-buffer new-name)
+ (set-visited-file-name new-name)
+ (set-buffer-modified-p nil)))))
(defun cj/delete-buffer-and-file ()
"Kill the current buffer and delete the file it visits."
(interactive)
(let ((filename (buffer-file-name)))
- (when filename
- (if (vc-backend filename)
- (vc-delete-file filename)
- (progn
- (delete-file filename t)
- (message "Deleted file %s" filename)
- (kill-buffer))))))
+ (when filename
+ (if (vc-backend filename)
+ (vc-delete-file filename)
+ (progn
+ (delete-file filename t)
+ (message "Deleted file %s" filename)
+ (kill-buffer))))))
(defun cj/copy-link-to-buffer-file ()
"Copy the full file:// path of the current buffer's source file to the kill ring."
(interactive)
(let ((file-path (buffer-file-name)))
- (when file-path
- (setq file-path (concat "file://" file-path))
- (kill-new file-path)
- (message "Copied file link to kill ring: %s" file-path))))
+ (when file-path
+ (setq file-path (concat "file://" file-path))
+ (kill-new file-path)
+ (message "Copied file link to kill ring: %s" file-path))))
(defun cj/copy-path-to-buffer-file-as-kill ()
"Copy the full path of the current buffer's file to the kill ring.
Signal an error if the buffer is not visiting a file."
(interactive)
(let ((path (buffer-file-name)))
- (if (not path)
- (user-error "Current buffer is not visiting a file")
- (kill-new path)
- (message "Copied file path: %s" path)
- path)))
+ (if (not path)
+ (user-error "Current buffer is not visiting a file")
+ (kill-new path)
+ (message "Copied file path: %s" path)
+ path)))
(defun cj/copy-whole-buffer ()
"Copy the entire contents of the current buffer to the kill ring.
@@ -151,8 +151,8 @@ Point and mark are left exactly where they were. No transient region
is created. A message is displayed when done."
(interactive)
(let ((contents (buffer-substring-no-properties (point-min) (point-max))))
- (kill-new contents)
- (message "Buffer contents copied to kill ring")))
+ (kill-new contents)
+ (message "Buffer contents copied to kill ring")))
(defun cj/clear-to-bottom-of-buffer ()
"Delete all text from point to the end of the current buffer.
@@ -168,6 +168,12 @@ Do not save the deleted text in the kill ring."
(delete-region (point) (point-min))
(message "Buffer contents removed to the beginning of the buffer."))
+(defun cj/copy-buffer-name ()
+ "Copy current buffer name to kill ring."
+ (interactive)
+ (kill-new (buffer-name))
+ (message "Copied: %s" (buffer-name)))
+
;; --------------------------- Buffer And File Keymap --------------------------
;; Buffer & file operations prefix and keymap
@@ -178,6 +184,7 @@ Do not save the deleted text in the kill ring."
"p" #'cj/print-buffer-ps
"d" #'cj/delete-buffer-and-file
"c" #'cj/copy-whole-buffer
+ "n" #'cj/copy-buffer-name
"t" #'cj/clear-to-top-of-buffer
"b" #'cj/clear-to-bottom-of-buffer
"x" #'erase-buffer