]> git.eshelyaron.com Git - dotfiles.git/commitdiff
ADDED: esy/log-buffer command, bound to C-c C-q in comint-mode-map
authorEshel Yaron <me@eshelyaron.com>
Wed, 13 Jul 2022 08:33:38 +0000 (11:33 +0300)
committerEshel Yaron <me@eshelyaron.com>
Wed, 13 Jul 2022 08:33:38 +0000 (11:33 +0300)
.emacs.d/esy.org

index c0b6fc4b8688420c47199400433c3580d2e9df22..d8d9ad993042a81e187de5794589f479967a7e61 100644 (file)
@@ -1683,6 +1683,45 @@ terminates, e.g. when pressing =C-d=.
     (keymap-set shell-mode-map "SPC" #'comint-magic-space))
 #+end_src
 
+** Save logs of =comint= buffers                                   :cmd:kbd:
+:PROPERTIES:
+:CUSTOM_ID: comint-log-buffer
+:CreatedAt: <2022-07-13 Wed>
+:CapturedAt:
+:CapturedAs: Emacs configuration fragment
+:END:
+
+#+begin_src emacs-lisp
+  (defvar esy/logs-directory "~/logs"
+    "Directory where some log files will be saved.")
+
+  (defvar-local esy/log-buffer-filename nil
+    "File in which the current buffer is logged.")
+
+  (defun esy/log-buffer ()
+    "Save the current buffer under `esy/logs-directory'."
+    (interactive)
+    (let ((filename (or esy/log-buffer-filename
+                        (setq esy/log-buffer-filename
+                              (expand-file-name
+                               (concat mode-name
+                                       "_"
+                                       (format-time-string
+                                        "%Y%m%d%H%M%S"
+                                        (current-time))
+                                       ".log")
+                               esy/logs-directory)))))
+      (save-restriction
+        (widen)
+        (write-region (point-min)
+                      (point-max)
+                      filename))))
+
+  (with-eval-after-load 'comint
+    (keymap-set comint-mode-map "C-c C-q" #'esy/log-buffer))
+
+#+end_src
+
 * Misc. settings
 :PROPERTIES:
 :CUSTOM_ID: misc