cat function

This commit is contained in:
EliasVincent 2025-01-06 22:25:05 +01:00
parent b12c9de2ad
commit b5c13c5b3d
1 changed files with 37 additions and 0 deletions

View File

@ -162,3 +162,40 @@
("C-TAB" . 'copilot-accept-completion-by-word)
("C-<tab>" . 'copilot-accept-completion-by-word)))
(whole-line-or-region-global-mode 1)
;; very clean me like
;; (defun concatenate-org-files (directory)
;; "Concatenate all .org files in DIRECTORY into a new buffer."
;; (interactive "DDirectory: ")
;; (let ((output-buffer (generate-new-buffer "*Concatenated Org Files*"))
;; (org-files (directory-files-recursively directory "\\.org$")))
;; (with-current-buffer output-buffer
;; (dolist (file org-files)
;; (insert-file-contents file)
;; (insert "\n\n"))
;; (org-mode)
;; (goto-char (point-min)))
;; (switch-to-buffer output-buffer)))
(defun concatenate-files-by-extension (directory extension)
"Concatenate all files with EXTENSION in DIRECTORY into a new buffer."
(interactive
(list
(read-directory-name "Directory: ")
(read-string "File extension (without dot): ")))
(let* ((file-regex (concat "\\." (regexp-quote extension) "$"))
(output-buffer-name (format "*Concatenated %s Files*" (upcase extension)))
(output-buffer (generate-new-buffer output-buffer-name))
(files (directory-files-recursively directory file-regex)))
(if (null files)
(message "No %s files found in the specified directory." extension)
(with-current-buffer output-buffer
(dolist (file files)
(unless (= (point-min) (point))
(insert "\n\n"))
(insert-file-contents file))
(goto-char (point-min))
(when (string= extension "org")
(org-mode)))
(switch-to-buffer output-buffer)
(message "Concatenated %d %s files." (length files) extension))))