<commit_before>;; --- dot emacs ---
;; Author:  <NAME> <tj at tjmaynes dot com>
;; Website: https://tjmaynes.com/

(defun utilities/ensure-file-location-exists (directory filename)
  (let ((file-location (format "%s/%s" directory filename)))
    (unless (file-exists-p file-location)
      (write-region "" nil file-location))
    file-location))

(defun utilities/get-environment-variable (env-name)
  (let ((value (getenv env-name)))
    (if (not value) (error (format "Missing environment variable: %s." env-name)))
    value))

(defun utilities/pt-pbpaste ()
  "Paste data from pasteboard."
  (interactive)
  (shell-command-on-region
   (point)
   (if mark-active (mark) (point)) "pbpaste" nil t))

(defun utilities/pt-pbcopy ()
  "Copy region to pasteboard."
  (interactive)
  (print (mark))
  (when mark-active
    (shell-command-on-region (point) (mark) "pbcopy")
    (kill-buffer "*Shell Command Output*")))

(defun utilities/read-json-file (json-file)
  (require 'json)
  (let* ((json-object-type 'hash-table)
	 (json-array-type 'list)
	 (json-key-type 'string)
	 (data (json-read-file json-file)))
    data))

(defvar package-manager/package-manager-refreshed nil)

(defun package-manager/package-manager-refresh-once ()
  (when (not package-manager/package-manager-refreshed)
    (setq package-manager/package-manager-refreshed t)
    (package-refresh-contents)))

(defun package-manager/ensure-packages-installed (&rest packages)
  (dolist (package packages)
    (when (not (package-installed-p package))
      (package-manager/package-manager-refresh-once)
      (package-install package))))

(defun package-manager/setup ()
  (setq package-enable-at-startup nil)
  (package-initialize)
  (add-to-list 'package-archives
	       '("melpa" . "https://melpa.org/packages/") t)
  (add-to-list 'package-archives
	       '("melpa-stable" . "https://stable.melpa.org/packages/") t)
  (add-to-list 'package-archives
	       '("gnu" . "https://elpa.gnu.org/packages/") t))

(defun backup/setup ()
  (package-manager/ensure-packages-installed 'magit)  
  (setq backup-by-copying t
	backup-directory-alist `((".*" . ,temporary-file-directory))
	auto-save-file-name-transforms `((".*" ,temporary-file-directory t))
	delete-old-versions t
	kept-new-versions 6
	kept-old-versions 2
	version-control t))

(defun key-bindings/setup ()
  (global-set-key (kbd "C-c m") 'gnus)
  (global-set-key (kbd "C-c g") 'magit-status)
  (global-set-key (kbd "C-c p") 'package-list-packages)
  (global-set-key (kbd "C-c 3") 'w3m-goto-url)
  (global-set-key (kbd "C-c n") 'elfeed)
  (global-set-key (kbd "C-c w") 'w3m-browse-url)
  (global-set-key (kbd "C-c t") 'eshell)
  (global-set-key (kbd "C-c r") 'irc)
  (global-set-key (kbd "C-c e p") 'emms-play-directory)
  (global-set-key (kbd "C-c e <left>") 'emms-previous)
  (global-set-key (kbd "C-c e <right>") 'emms-next)
  (global-set-key (kbd "C-c e <up>") 'emms-play)
  (global-set-key (kbd "C-c e <down>") 'emms-stop)
  (global-set-key (kbd "C-c e r") 'emms-streams)
  (global-set-key (kbd "C-c e s") 'emms-shuffle)
  (global-set-key (kbd "C-c e o") 'emms-playlist-mode-go)
  (global-set-key (kbd "C-x <left>") 'windmove-left)
  (global-set-key (kbd "C-x <right>") 'windmove-right)
  (global-set-key (kbd "C-x <up>") 'windmove-up)
  (global-set-key (kbd "C-x <down>") 'windmove-down)
  (global-set-key (kbd "C-x C-d") 'insert-journal-date)
  (global-set-key (kbd "C-x C-i") 'indent-region)
  (global-set-key (kbd "C-u") 'undo)
  (global-set-key (kbd "M-]") 'doc-view-next-page)
  (global-set-key (kbd "M-[") 'doc-view-previous-page)
  (global-set-key (kbd "C-x C-y") 'utilities/pt-pbpaste)
  (global-set-key (kbd "C-x M-w") 'utilities/pt-pbcopy))

(defun development/file-setup ()
  (package-manager/ensure-packages-installed 'yaml-mode 'dockerfile-mode 'nix-mode)
  (setq mode-require-final-newline t)
  (prefer-coding-system 'utf-8)
  (set-default-coding-systems 'utf-8)
  (set-terminal-coding-system 'utf-8)
  (set-keyboard-coding-system 'utf-8))

(defun development/html-setup ()
  (package-manager/ensure-packages-installed 'web-mode)
  (setq web-mode-markup-indent-offset 2
	web-mode-code-indent-offset 2
	web-mode-css-indent-offset 2
	web-mode-enable-auto-pairing t
	web-mode-enable-auto-expanding t
	web-mode-enable-css-colorization t)
  (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode)))

(defun development/emacs-lisp-mode-hook ()
  (paredit-mode +1)
  (prettify-symbols-mode +1)
  (show-paren-mode +1))

(defun development/emacs-lisp-setup ()
  (package-manager/ensure-packages-installed 'paredit)
  (require 'paredit)
  (add-hook 'emacs-lisp-mode-hook 'development/emacs-lisp-mode-hook))

(defun development/set-exec-path-from-shell-PATH ()
  (let ((path-from-shell (replace-regexp-in-string "[ \t\n]*$" "" (shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
    (setenv "SHELL" "/bin/zsh")
    (setenv "PATH" path-from-shell)
    (setq exec-path (append exec-path '("/usr/local/bin"))
	  eshell-path-env path-from-shell
	  exec-path (split-string path-from-shell path-separator))))

(defun development/shell-setup ()
  (when window-system (development/set-exec-path-from-shell-PATH)))

(defun development/setup ()
  (development/file-setup)
  (development/html-setup)
  (development/emacs-lisp-setup)
  (development/shell-setup))

(defun theme/cli-setup ()
  (package-manager/ensure-packages-installed 'zenburn-theme)
  (load-theme 'zenburn t))

(defun theme/setup (theme-config)
  (let ((initial-message (gethash "initial-message" theme-config))
	(bookmarks-file (gethash "bookmarks-file" theme-config)))
    (setq inhibit-splash-screen t
	  initial-scratch-message ""
	  inhibit-startup-echo-area-message initial-message
	  mac-allow-anti-aliasing t
	  scroll-step 1000
	  scroll-conservatively 1000
	  redisplay-dont-pause t
	  scroll-preserve-screen-position 1<commit_msg>Add clojure support<commit_after>;; --- dot emacs ---
;; Author:  <NAME> <tj at tjmaynes dot com>
;; Website: https://tjmaynes.com/

(defun utilities/ensure-file-location-exists (directory filename)
  (let ((file-location (format "%s/%s" directory filename)))
    (unless (file-exists-p file-location)
      (write-region "" nil file-location))
    file-location))

(defun utilities/get-environment-variable (env-name)
  (let ((value (getenv env-name)))
    (if (not value) (error (format "Missing environment variable: %s." env-name)))
    value))

(defun utilities/pt-pbpaste ()
  "Paste data from pasteboard."
  (interactive)
  (shell-command-on-region
   (point)
   (if mark-active (mark) (point)) "pbpaste" nil t))

(defun utilities/pt-pbcopy ()
  "Copy region to pasteboard."
  (interactive)
  (print (mark))
  (when mark-active
    (shell-command-on-region (point) (mark) "pbcopy")
    (kill-buffer "*Shell Command Output*")))

(defun utilities/read-json-file (json-file)
  (require 'json)
  (let* ((json-object-type 'hash-table)
	 (json-array-type 'list)
	 (json-key-type 'string)
	 (data (json-read-file json-file)))
    data))

(defvar package-manager/package-manager-refreshed nil)

(defun package-manager/package-manager-refresh-once ()
  (when (not package-manager/package-manager-refreshed)
    (setq package-manager/package-manager-refreshed t)
    (package-refresh-contents)))

(defun package-manager/ensure-packages-installed (&rest packages)
  (dolist (package packages)
    (when (not (package-installed-p package))
      (package-manager/package-manager-refresh-once)
      (package-install package))))

(defun package-manager/setup ()
  (setq package-enable-at-startup nil)
  (package-initialize)
  (add-to-list 'package-archives
	       '("melpa" . "https://melpa.org/packages/") t)
  (add-to-list 'package-archives
	       '("melpa-stable" . "https://stable.melpa.org/packages/") t)
  (add-to-list 'package-archives
	       '("gnu" . "https://elpa.gnu.org/packages/") t))

(defun backup/setup ()
  (package-manager/ensure-packages-installed 'magit)  
  (setq backup-by-copying t
	backup-directory-alist `((".*" . ,temporary-file-directory))
	auto-save-file-name-transforms `((".*" ,temporary-file-directory t))
	delete-old-versions t
	kept-new-versions 6
	kept-old-versions 2
	version-control t))

(defun key-bindings/setup ()
  (global-set-key (kbd "C-c m") 'gnus)
  (global-set-key (kbd "C-c g") 'magit-status)
  (global-set-key (kbd "C-c p") 'package-list-packages)
  (global-set-key (kbd "C-c 3") 'w3m-goto-url)
  (global-set-key (kbd "C-c n") 'elfeed)
  (global-set-key (kbd "C-c w") 'w3m-browse-url)
  (global-set-key (kbd "C-c t") 'eshell)
  (global-set-key (kbd "C-c r") 'irc)
  (global-set-key (kbd "C-c e p") 'emms-play-directory)
  (global-set-key (kbd "C-c e <left>") 'emms-previous)
  (global-set-key (kbd "C-c e <right>") 'emms-next)
  (global-set-key (kbd "C-c e <up>") 'emms-play)
  (global-set-key (kbd "C-c e <down>") 'emms-stop)
  (global-set-key (kbd "C-c e r") 'emms-streams)
  (global-set-key (kbd "C-c e s") 'emms-shuffle)
  (global-set-key (kbd "C-c e o") 'emms-playlist-mode-go)
  (global-set-key (kbd "C-x <left>") 'windmove-left)
  (global-set-key (kbd "C-x <right>") 'windmove-right)
  (global-set-key (kbd "C-x <up>") 'windmove-up)
  (global-set-key (kbd "C-x <down>") 'windmove-down)
  (global-set-key (kbd "C-x C-d") 'insert-journal-date)
  (global-set-key (kbd "C-x C-i") 'indent-region)
  (global-set-key (kbd "C-u") 'undo)
  (global-set-key (kbd "M-]") 'doc-view-next-page)
  (global-set-key (kbd "M-[") 'doc-view-previous-page)
  (global-set-key (kbd "C-x C-y") 'utilities/pt-pbpaste)
  (global-set-key (kbd "C-x M-w") 'utilities/pt-pbcopy))

(defun development/file-setup ()
  (package-manager/ensure-packages-installed 'yaml-mode 'dockerfile-mode 'nix-mode)
  (setq mode-require-final-newline t)
  (prefer-coding-system 'utf-8)
  (set-default-coding-systems 'utf-8)
  (set-terminal-coding-system 'utf-8)
  (set-keyboard-coding-system 'utf-8))

(defun development/html-setup ()
  (package-manager/ensure-packages-installed 'web-mode)
  (setq web-mode-markup-indent-offset 2
	web-mode-code-indent-offset 2
	web-mode-css-indent-offset 2
	web-mode-enable-auto-pairing t
	web-mode-enable-auto-expanding t
	web-mode-enable-css-colorization t)
  (add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode)))

(defun development/emacs-lisp-mode-hook ()
  (paredit-mode +1)
  (prettify-symbols-mode +1)
  (show-paren-mode +1))

(defun development/emacs-lisp-setup ()
  (package-manager/ensure-packages-installed 'paredit)
  (require 'paredit)
  (add-hook 'emacs-lisp-mode-hook 'development/emacs-lisp-mode-hook))

(defun development/set-exec-path-from-shell-PATH ()
  (let ((path-from-shell (replace-regexp-in-string "[ \t\n]*$" "" (shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
    (setenv "SHELL" "/bin/zsh")
    (setenv "PATH" path-from-shell)
    (setq exec-path (append exec-path '("/usr/local/bin"))
	  eshell-path-env path-from-shell
	  exec-path (split-string path-from-shell path-separator))))

(defun development/shell-setup ()
  (when window-system (development/set-exec-path-from-shell-PATH)))

(defun development/clojure-mode-hook ()
  (paredit-mode +1)
  (enable-show-paren-mode)
  (define-key clojure-mode-map (kbd "C-c C-a") 'align-cljlet)
  (dolist (macro '(fresh conde run run* for-all for-map go go-loop
			 for> doseq> fn> defn> defprotocol> gen-for))
    (put-clojure-indent macro 'defun))
  (clj-refactor-mode 1)
  (cljr-add-keybindings-with-prefix "C-c C-v")
  (local-set-key (kbd "RET") 'newline-and-indent))

(defun development/clojure-setup ()
  (package-manager/ensure-packages-installed 'clojure-mode 'cider 'align-cljlet 'paredit 'clj-refactor)
  (setq cider-prompt-for-symbol nil)
  (add-hook 'clojure-mode-hook 'development/clojure-mode-hook)
  (add-hook 'cider-repl-mode-hook 'paredit-mode))

(defun development/setup ()
  (development/file-setup)
  (development/html-setup)
  (development/emacs-lisp-setup)
  (development/clojure-setup)
  (development/shell-setup))

(defun theme/cli-setup ()
  (package-manager/ensure-packages-installed 'zenburn-theme)
  (load-theme 'zenburn t))

(defun theme/setup (theme-config)
  (let ((initial-message (gethash "initial-message" theme-config))
	(bookmarks-file (gethash "bookmarks-file" theme-config)))
    (setq inhibit-splash-screen t
	  initial-scratch-message ""
	  inhibit-startup-echo-area-message initial-message
	  mac-allow-anti-aliasing t
	  scroll-step 1000
	  scroll-conservatively 1000
	  redisplay-dont-pause t
	  scroll-preserve-screen-position 1
{'fraction_non_alphanumeric': 0.18303069259199742, 'fraction_numerical': 0.004017354973485457, 'mean_word_length': 3.732699619771863, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 28, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2522489', 'n_tokens_mistral': 4932, 'n_tokens_neox': 4825, 'n_words': 934}