<commit_before>; Call the debugger when an error is signaled and not handled.
(setq debug-on-error t)
; Disable 'Package cl is deprecated' message.
; https://github.com/kiwanami/emacs-epc/issues/35#issuecomment-660639327
(setq byte-compile-warnings '(cl-functions))
; Work around a bug where esup tries to step into the byte-compiled version of
; `cl-lib', and fails horribly.
; See https://github.com/jschaf/esup/issues/54#issuecomment-651247749.
(setq esup-depth 0)
; Helper function for determining system type.
(defun l/os (system)
  (interactive)
  (string-equal system-type system))

; Try very hard to not split existing windows to open up links and other new
; buffers. https://stackoverflow.com/a/1856069/437583
(setq same-window-regexps '("."))

; If on Mac, make Emacs aware of special paths, esp. Homebrew (for `exec-path').
; Unfortunately, setting "PATH" does not automatically set `exec-path'. So, we
; do both for consistency. See
; http://ergoemacs.org/emacs/emacs_env_var_paths.html.
(if (l/os "darwin")
  (let*
    ((HOME (getenv "HOME"))
     (PATH (getenv "PATH"))
     (paths `(
      ,(concat HOME "/syscfg/script")
      ,(concat HOME "/bin")
      ,(concat HOME "/.nix-profile/bin"))))
    (setenv "PATH" (concat (mapconcat 'identity paths ":") ":" PATH))
    ; The way in which `exec-path' is set here is hacky. It appears that
    ; exec-directory has little bearing to $PATH, so we just prepend $PATH to
    ; exec-directory and hope for the best. It could be that exec-directory is
    ; useless, but we give upstream code the benefit of the doubt.
    (setq exec-path
      (append
        (split-string (getenv "PATH") ":")
        (list exec-directory)))))

(if (l/os "gnu/linux")
  (let*
    ((HOME (getenv "HOME"))
     (PATH (getenv "PATH"))
     (paths `(
      ,(concat HOME "/syscfg/script")
      ,(concat HOME "/.local/bin"))))
    (setenv "PATH" (concat (mapconcat 'identity paths ":") ":" PATH))
    (setq exec-path
      (append
        (split-string (getenv "PATH") ":")
        (list exec-directory)))))

; Increase garbage collection threshhold during startup to inhibit its
; activation. This way, startup can be a little bit faster. See
; https://github.com/nilcons/emacs-use-package-fast.
(setq gc-cons-threshold 64000000)
(add-hook 'after-init-hook #'(lambda ()
  ;; restore after startup
  (setq gc-cons-threshold 800000)))

; For mac, increase initial frame size manually because we are not on XMonad.
(when (l/os "darwin")
  (add-to-list 'default-frame-alist '(height . 71))
  (add-to-list 'default-frame-alist '(width . 80)))

; Bootstrap `use-package'. See
; http://www.lunaryorn.com/posts/my-emacs-configuration-with-use-package.html.
(require 'package)
(setq package-enable-at-startup nil)
(setq package-archives (append '(
  ("melpa" . "https://melpa.org/packages/")
  ("org" . "https://orgmode.org/elpa/")) package-archives))

(package-initialize)
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package)
  (eval-when-compile (require 'use-package)))

; Ensure that all packages handled by use-package are always installed if not
; present.
(setq use-package-always-ensure t)

; Macros.
; See
; http://emacs.stackexchange.com/questions/17420/how-to-pass-a-parameter-together-with-function.
(defmacro l/define-key-args (map key func &rest args)
  `(define-key ,map ,key (lambda () (interactive) (,func ,@args))))

(defmacro l/add-hook-args (hook func &rest args)
  `(add-hook ,hook (lambda () (interactive) (,func ,@args))))

; Disable "*GNU Emacs*" startup buffer.
(setq inhibit-startup-screen t)

; Suppress defadvice redefinition warnings (such as by third party packages).
(setq ad-redefinition-action 'accept)

; Disable all version control minor modes (e.g., vc-git).
(setq vc-handled-backends nil)

; Emulate TextMate's "auto-paired characters".
(electric-pair-mode 1)

; Put all auto-saves/backups to the temp directory.
(setq backup-directory-alist
  `((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
  `((".*" ,temporary-file-directory t)))

; Disable backups when on Mac. It really messes up org-mode's inter-file links
; for some reason, where a link to a file is replaced with a link to that file's
; backup when that file is edited. Gross.
(if (l/os "darwin")
  (setq make-backup-files nil))

; Save minibuffer history across sessions, limited to 1000 entries.
(savehist-mode 1)
(setq history-length 1000)

; Use chromium-browser for opening URLs. See
; https://stackoverflow.com/a/4506458.
(setq
  browse-url-browser-function 'browse-url-generic
  browse-url-generic-program
    (cond
      ((string-match "macbookpro" system-name) "google-chrome-mac.sh")
      (t "chromium-browser")))

; Scroll more like Vim (no jumping around).
(setq
  scroll-margin 3
  scroll-conservatively 100000
  scroll-preserve-screen-position 1)

; `M-x shell'
; Disable command echo.
(setq comint-process-echoes t)

; Set default line length (as used by 'fill-paragraph) to be 80 characters.
(setq-default fill-column 80)

; Add newline (silently) at the end of a file, just like Vim.
(setq require-final-newline t)

; Ignore "File changed on disk" minibuffer modal prompt for git commit/rebase
; messages (even with this setting, we can always just undo to get it back
; anyway.)
(setq revert-without-query '("^COMMIT_EDITMSG" "^git-rebase-todo"))

; NixOS: This enables the various emacs scripts that are installed by
; nixos-rebuild. The script below is taken from
; https://gitorious.org/goibhniu/configuration-files. In particular, this ends<commit_msg>emacs: prefer to use qutebrowser over chromium<commit_after>; Call the debugger when an error is signaled and not handled.
(setq debug-on-error t)
; Disable 'Package cl is deprecated' message.
; https://github.com/kiwanami/emacs-epc/issues/35#issuecomment-660639327
(setq byte-compile-warnings '(cl-functions))
; Work around a bug where esup tries to step into the byte-compiled version of
; `cl-lib', and fails horribly.
; See https://github.com/jschaf/esup/issues/54#issuecomment-651247749.
(setq esup-depth 0)
; Helper function for determining system type.
(defun l/os (system)
  (interactive)
  (string-equal system-type system))

; Try very hard to not split existing windows to open up links and other new
; buffers. https://stackoverflow.com/a/1856069/437583
(setq same-window-regexps '("."))

; If on Mac, make Emacs aware of special paths, esp. Homebrew (for `exec-path').
; Unfortunately, setting "PATH" does not automatically set `exec-path'. So, we
; do both for consistency. See
; http://ergoemacs.org/emacs/emacs_env_var_paths.html.
(if (l/os "darwin")
  (let*
    ((HOME (getenv "HOME"))
     (PATH (getenv "PATH"))
     (paths `(
      ,(concat HOME "/syscfg/script")
      ,(concat HOME "/bin")
      ,(concat HOME "/.nix-profile/bin"))))
    (setenv "PATH" (concat (mapconcat 'identity paths ":") ":" PATH))
    ; The way in which `exec-path' is set here is hacky. It appears that
    ; exec-directory has little bearing to $PATH, so we just prepend $PATH to
    ; exec-directory and hope for the best. It could be that exec-directory is
    ; useless, but we give upstream code the benefit of the doubt.
    (setq exec-path
      (append
        (split-string (getenv "PATH") ":")
        (list exec-directory)))))

(if (l/os "gnu/linux")
  (let*
    ((HOME (getenv "HOME"))
     (PATH (getenv "PATH"))
     (paths `(
      ,(concat HOME "/syscfg/script")
      ,(concat HOME "/.local/bin"))))
    (setenv "PATH" (concat (mapconcat 'identity paths ":") ":" PATH))
    (setq exec-path
      (append
        (split-string (getenv "PATH") ":")
        (list exec-directory)))))

; Increase garbage collection threshhold during startup to inhibit its
; activation. This way, startup can be a little bit faster. See
; https://github.com/nilcons/emacs-use-package-fast.
(setq gc-cons-threshold 64000000)
(add-hook 'after-init-hook #'(lambda ()
  ;; restore after startup
  (setq gc-cons-threshold 800000)))

; For mac, increase initial frame size manually because we are not on XMonad.
(when (l/os "darwin")
  (add-to-list 'default-frame-alist '(height . 71))
  (add-to-list 'default-frame-alist '(width . 80)))

; Bootstrap `use-package'. See
; http://www.lunaryorn.com/posts/my-emacs-configuration-with-use-package.html.
(require 'package)
(setq package-enable-at-startup nil)
(setq package-archives (append '(
  ("melpa" . "https://melpa.org/packages/")
  ("org" . "https://orgmode.org/elpa/")) package-archives))

(package-initialize)
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package)
  (eval-when-compile (require 'use-package)))

; Ensure that all packages handled by use-package are always installed if not
; present.
(setq use-package-always-ensure t)

; Macros.
; See
; http://emacs.stackexchange.com/questions/17420/how-to-pass-a-parameter-together-with-function.
(defmacro l/define-key-args (map key func &rest args)
  `(define-key ,map ,key (lambda () (interactive) (,func ,@args))))

(defmacro l/add-hook-args (hook func &rest args)
  `(add-hook ,hook (lambda () (interactive) (,func ,@args))))

; Disable "*GNU Emacs*" startup buffer.
(setq inhibit-startup-screen t)

; Suppress defadvice redefinition warnings (such as by third party packages).
(setq ad-redefinition-action 'accept)

; Disable all version control minor modes (e.g., vc-git).
(setq vc-handled-backends nil)

; Emulate TextMate's "auto-paired characters".
(electric-pair-mode 1)

; Put all auto-saves/backups to the temp directory.
(setq backup-directory-alist
  `((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
  `((".*" ,temporary-file-directory t)))

; Disable backups when on Mac. It really messes up org-mode's inter-file links
; for some reason, where a link to a file is replaced with a link to that file's
; backup when that file is edited. Gross.
(if (l/os "darwin")
  (setq make-backup-files nil))

; Save minibuffer history across sessions, limited to 1000 entries.
(savehist-mode 1)
(setq history-length 1000)

; Use different browsers for opening URLs, depending on the hostname. See
; https://stackoverflow.com/a/4506458.
(setq
  browse-url-browser-function 'browse-url-generic
  browse-url-generic-program
    (cond
      ((string-match "macbookpro" system-name) "google-chrome-mac.sh")
      (t "qutebrowser")))

; Scroll more like Vim (no jumping around).
(setq
  scroll-margin 3
  scroll-conservatively 100000
  scroll-preserve-screen-position 1)

; `M-x shell'
; Disable command echo.
(setq comint-process-echoes t)

; Set default line length (as used by 'fill-paragraph) to be 80 characters.
(setq-default fill-column 80)

; Add newline (silently) at the end of a file, just like Vim.
(setq require-final-newline t)

; Ignore "File changed on disk" minibuffer modal prompt for git commit/rebase
; messages (even with this setting, we can always just undo to get it back
; anyway.)
(setq revert-without-query '("^COMMIT_EDITMSG" "^git-rebase-todo"))

; NixOS: This enables the various emacs scripts that are installed by
; nixos-rebuild. The script below is taken from
; https://gitorious.org/goibhniu/configuration-files. In particular, this ends
{'fraction_non_alphanumeric': 0.13719376391982183, 'fraction_numerical': 0.015679287305122493, 'mean_word_length': 3.834625322997416, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 16, 'lorem ipsum': 0, 'www.': 2, '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': '184430', 'n_tokens_mistral': 3897, 'n_tokens_neox': 3670, 'n_words': 1178}