#+TITLE: Emacs literate config
+#+STARTUP: noindent
#+PROPERTY: header-args emacs-lisp :tangle config.el
* Header
(add-to-list 'load-path (concat user-emacs-directory path)))
(dolist (file '(re-pass-alike eng-paper-theme sedit-mouse))
- (require file))
+ (require file))
(setq w32-recognize-altgr 'nil)
"Use TRAMP to reopen the current buffer as root using doas."
(interactive)
(when buffer-file-name
- (find-alternate-file (concat "/doas:root@localhost:" buffer-file-name))))
+ (find-alternate-file (concat "/doas:root@localhost:" buffer-file-name))))
(defun sudo ()
"Use TRAMP to reopen the current buffer as root using sudo."
(interactive)
(when buffer-file-name
- (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name)))))
+ (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name)))))
#+END_SRC
* Packages
(setq-default TeX-master nil)
(add-to-list 'TeX-view-program-selection '(output-pdf "PDF Tools"))
(setq TeX-auto-save t
- TeX-parse-self t
- TeX-PDF-mode t
- TeX-source-correlate-start-server t)
+ TeX-parse-self t
+ TeX-PDF-mode t
+ TeX-source-correlate-start-server t)
(add-hook 'TeX-after-compilation-finished-functions
- #'TeX-revert-document-buffer))
+ #'TeX-revert-document-buffer))
#+END_SRC
** CSV Mode
#+BEGIN_SRC emacs-lisp
(setq markdown-special-ctrl-a/e t)
:bind
(:map markdown-mode-map
- ("M-<right>" . markdown-demote)
- ("M-<left>" . markdown-promote)
- ("M-<up>" . markdown-move-up)
- ("M-<down>" . markdown-move-down)
- ("C-M-u" . markdown-up-heading)
- ("C-M-b" . markdown-outline-previous-same-level)
- ("C-M-f" . markdown-outline-next-same-level)
- ("C-M-p" . markdown-outline-previous)
- ("C-M-n" . markdown-outline-next)))
+ ("M-<right>" . markdown-demote)
+ ("M-<left>" . markdown-promote)
+ ("M-<up>" . markdown-move-up)
+ ("M-<down>" . markdown-move-down)
+ ("C-M-u" . markdown-up-heading)
+ ("C-M-b" . markdown-outline-previous-same-level)
+ ("C-M-f" . markdown-outline-next-same-level)
+ ("C-M-p" . markdown-outline-previous)
+ ("C-M-n" . markdown-outline-next)))
(use-package edit-indirect :after 'markdown-mode)
#+END_SRC
(use-package sly
:config
(setq inferior-lisp-program "sbcl"
- sly-net-coding-system 'utf-8-unix
- sly-command-switch-to-existing-lisp 'always)
+ sly-net-coding-system 'utf-8-unix
+ sly-command-switch-to-existing-lisp 'always)
(let ((core (expand-file-name "~/sbcl.core-for-sly")))
(when (file-exists-p core)
- (setq sly-lisp-implementations (list `(sbcl ("sbcl" "--core" ,core))))))
+ (setq sly-lisp-implementations (list `(sbcl ("sbcl" "--core" ,core))))))
:bind
(:map sly-mrepl-mode-map
- (")" . (lambda () (interactive) (re/send-on-close-paren #'sly-mrepl-return)))
- ("]" . (lambda () (interactive) (re/balance-and-eval-sexp #'sly-mrepl-return)))
- ("C-c q" . re/sly-quit-current-lisp)))
+ (")" . (lambda () (interactive) (re/send-on-close-paren #'sly-mrepl-return)))
+ ("]" . (lambda () (interactive) (re/balance-and-eval-sexp #'sly-mrepl-return)))
+ ("C-c q" . re/sly-quit-current-lisp)))
#+END_SRC
*** Eldoc settings
Sly really doesn't play well with elodc in the minibuffer, so here are some settings to make it better.
#+BEGIN_SRC emacs-lisp
(add-to-list 'display-buffer-alist
- '("^\\*eldoc" display-buffer-in-direction
- (direction . 'down)
- (window-height . 4)))
+ '("^\\*eldoc" display-buffer-in-direction
+ (direction . 'down)
+ (window-height . 4)))
(keymap-global-set "C-c d" #'eldoc) ; force eldoc to show in minibuffer
(keymap-global-set "C-c D" #'eldoc-doc-buffer) ; open eldoc buffer when it's getting spammed
#+END_SRC
(use-package geiser
:config
(if (equal system-type 'windows-nt)
- (setq geiser-chicken-binary '("C:/tools/chicken/bin/csi.exe" "-:c"))
+ (setq geiser-chicken-binary '("C:/tools/chicken/bin/csi.exe" "-:c"))
(setq geiser-chicken-binary "csi -:c"))
(setq scheme-program-name geiser-chicken-binary
- geiser-active-implementations '(chicken))
+ geiser-active-implementations '(chicken))
(add-hook 'scheme-mode-hook 'geiser-mode)
:bind
(:map geiser-repl-mode-map
- (")" . (lambda () (interactive) (re/send-on-close-paren #'geiser-repl-maybe-send)))
- ("]" . (lambda () (interactive) (re/balance-and-eval-sexp #'geiser-repl-maybe-send)))))
+ (")" . (lambda () (interactive) (re/send-on-close-paren #'geiser-repl-maybe-send)))
+ ("]" . (lambda () (interactive) (re/balance-and-eval-sexp #'geiser-repl-maybe-send)))))
(use-package geiser-chicken :after 'geiser)
#+END_SRC
(use-package forth-mode)
#+END_SRC
** ORG
-Loading in org customizations from a separate file for now. Maybe tangle that file from here in the future
+*** Load in the package and set bindings
#+BEGIN_SRC emacs-lisp
(use-package org
:config
(require 'org-mouse)
- (require 're-org)
:bind
(("C-c l" . org-store-link)
("C-c a" . org-agenda)
:bind
(("C-c t" . org-transclusion-mode)))
#+END_SRC
+*** Configuration
+**** General options
+#+BEGIN_SRC emacs-lisp
+ (with-eval-after-load 'org-mode (add-to-list 'org-export-backends 'md))
+
+ (setq org-startup-indented t
+ org-indent-indentation-per-level tab-width
+ org-startup-folded 'fold
+ org-startup-with-inline-images t
+ org-cycle-inline-images-display t
+ org-cycle-separator-lines 0
+ org-blank-before-new-entry '((heading) (plain-list-item . auto))
+ org-M-RET-may-split-line nil
+ org-treat-S-cursor-todo-selection-as-state-change nil
+ org-treat-insert-todo-heading-as-state-change nil
+ org-table-export-default-format "orgtbl-to-csv"
+ org-list-allow-alphabetical t
+ org-fold-catch-invisible-edits 'show-and-error
+ org-ellipsis "↴"
+ org-tags-column 0
+ org-reverse-note-order t
+ org-enforce-todo-dependencies t
+ org-enforce-todo-checkbox-dependencies t
+ org-fontify-done-headline nil
+ org-fontify-todo-headline nil
+ org-goto-interface 'outline-path-completion
+ org-outline-path-complete-in-steps nil
+ org-goto-auto-isearch nil
+ org-special-ctrl-a/e t
+ org-special-ctrl-k t
+ org-return-follows-link t
+ org-yank-adjusted-subtrees t)
+#+END_SRC
+**** Time Clocking
+#+BEGIN_SRC emacs-lisp
+(org-clock-persistence-insinuate)
+(setq org-clock-history-length 10
+ org-clock-in-resume t
+ org-clock-out-remove-zero-time-clocks t
+ org-clock-persist t
+ org-clock-persist-query-resume nil
+ org-clock-report-include-clocking-task t
+ org-time-stamp-rounding-minutes '(1 1))
+#+END_SRC
+**** Agenda and Capture
+#+BEGIN_SRC emacs-lisp
+(add-hook 'org-agenda-mode-hook #'hl-line-mode)
+
+(setq org-agenda-files (append '("~/org/")
+ (file-expand-wildcards "~/projects/*/"))
+ org-refile-targets '((nil :maxlevel . 9)
+ (org-agenda-files :maxlevel . 9))
+ org-refile-use-outline-path 'file
+ org-refile-allow-creating-parent-nodes 'confirm
+ org-tag-alist '(("call" . ?c)
+ ("email" . ?e)
+ ("errand" . ?r)
+ ("jobpc" . ?j)
+ ("license" . ?l)
+ ("meeting" . ?m)
+ ("open" . ?o))
+ org-tags-exclude-from-inheritance '("open")
+ org-todo-keywords '((sequence "TODO(t)" "WAITING(w@)" "|" "DONE(d)" "BELAYED(b@)" "GIVEN(g@)")
+ (sequence "MEETING(m)" "|" "MET(M)"))
+ org-todo-keyword-faces '(("WAITING" :foreground "#e85400" :weight bold)
+ ("MEETING" :foreground "#315e9a" :weight bold))
+ org-agenda-restore-windows-after-quit t
+ org-agenda-start-on-weekday nil
+ org-agenda-compact-blocks t
+ org-agenda-span 'day
+ org-deadline-warning-days 30
+ org-agenda-window-setup 'current-window
+ org-agenda-time-grid '((daily today remove-match)
+ (600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800 1900)
+ " ――――― "
+ "")
+ org-agenda-tags-column 50
+ org-agenda-skip-additional-timestamps-same-entry t
+ org-agenda-skip-deadline-if-done t
+ org-agenda-skip-scheduled-if-done t
+ org-agenda-prefix-format '((agenda . " %?-12t% s")
+ (todo . " ")
+ (tags . " ")
+ (search . " "))
+ org-agenda-scheduled-leaders '("BOOKED: " "Booked %2d d. ago: ")
+ org-agenda-deadline-leaders '("DEADLINE: " "In %3d d.: " "%2d d. ago: ")
+ org-read-date-prefer-future 'time
+ org-agenda-custom-commands '(("f" "Maybe Someday" tags "someday" ((org-agenda-overriding-header "SOMEDAY:")))
+ ("i" "Inbox" tags "inbox" ((org-agenda-overriding-header "INBOX:")))
+ ("l" "Licenses" tags "license" ((org-agenda-overriding-header "LICENSES:")))
+ ("n" "Next Actions" tags-todo "-recurring/TODO" ((org-agenda-overriding-header "NEXT:")))
+ ("p" "JobPCs" tags "jobpc" ((org-agenda-overriding-header "JOB PCS:")))
+ ("u" "Undertakings" tags "open" ((org-agenda-overriding-header "UNDERTAKINGS:")))
+ ("w" "Waiting" todo "WAITING" ((org-agenda-overriding-header "WAITING:")))
+ ("o" "Overview" ((agenda "")
+ (tags "inbox" ((org-agenda-overriding-header "\nINBOX:")))
+ (tags-todo "-recurring/TODO" ((org-agenda-overriding-header "\nNEXT:")
+ (org-agenda-max-entries 10)))
+ (tags "open" ((org-agenda-overriding-header "\nUNDERTAKINGS:")))
+ (todo "WAITING" ((org-agenda-overriding-header "\nWAITING:"))))))
+ org-agenda-start-with-log-mode t
+ org-agenda-log-mode-items '(closed clock state)
+ org-log-done 'time
+ org-log-into-drawer nil
+ org-log-state-notes-insert-after-drawers t
+ org-log-state-notes-into-drawer nil
+ org-capture-templates '(("i" "Inbox" entry
+ (file "gtd.org")
+ "* %^{Description} :inbox:\n%U\n%?"
+ :prepend t
+ :clock-in t
+ :clock-resume t)
+ ("m" "Meeting" entry
+ (file "gtd.org")
+ "* MEETING %^{Description} :meeting:\n%^{Scheduled:}T\n%?"
+ :prepend t
+ :clock-in t
+ :clock-resume t)
+ ("p" "Phone Call" entry
+ (file "gtd.org")
+ "* %^{Description} :call:\n%U\n%?"
+ :prepend t
+ :clock-in t
+ :clock-resume t)))
+#+END_SRC
+**** IDs
+#+BEGIN_SRC emacs-lisp
+(setq org-id-link-to-org-use-id 'create-if-interactive-and-no-custom-id
+ org-id-method 'ts
+ org-clone-delete-id t
+ org-attach-id-to-path-function-list '(org-attach-id-ts-folder-format
+ org-attach-id-uuid-folder-format))
+
+(defun re/org-auto-generate-ids-in-file ()
+ "Add ID properties to all headlines in the current
+ file which do not already have one."
+ (interactive)
+ (org-map-entries 'org-id-get-create))
+
+(defun re/org-save-all ()
+ "Save all `org-agenda-files' without user confirmation."
+ (interactive)
+ (message "Saving all org-agenda-files buffers...")
+ (save-some-buffers t
+ (lambda ()
+ (when (member (buffer-file-name) org-agenda-files) t)))
+ (message "Saving all org-agenda-files buffers... done"))
+
+(advice-add 'org-refile :after (lambda (&rest _) (re/org-save-all)))
+#+END_SRC
+**** Archiving
+#+BEGIN_SRC emacs-lisp
+(defun re/org-archive-all ()
+ "Archive all tasks marked `DONE' in agenda files"
+ (interactive)
+ (message "Archiving all completed tasks in org-agenda-files...")
+ (org-map-entries (lambda ()
+ (org-archive-subtree)
+ (setq org-map-continue-from (org-element-property
+ :begin
+ (org-element-at-point))))
+ "/DONE"
+ 'agenda)
+ (message "Archiving all completed tasks in org-agenda-files... done"))
+
+(setq org-archive-location (concat "~/org/old.org_keep::datetree/")
+ org-agenda-text-search-extra-files '(agenda-archives))
+
+(add-to-list 'auto-mode-alist '("\\.org_keep\\'" . org-mode))
+#+END_SRC
** HOWM
On-again, off-again relationship with this one
+*** Load package and add bindings
#+BEGIN_SRC emacs-lisp
-(use-package howm
- :config
- (require 're-howm)
- :bind
- (("<f6>" . howm-menu)
- ("S-<f6>" . re/howm-menu-new-frame)
- :map howm-mode-map
- ("C-c , k" . re/howm-create-keyword)
- ("C-c , =" . howm-narrow-to-memo)))
+ (use-package howm
+ :bind
+ (("<f6>" . howm-menu)
+ ("S-<f6>" . re/howm-menu-new-frame)
+ :map howm-mode-map
+ ("C-c , k" . re/howm-create-keyword)
+ ("C-c , =" . howm-narrow-to-memo)))
#+END_SRC
+*** Config
+**** General settings
+#+BEGIN_SRC emacs-lisp
+ (setq howm-template '("= %title%cursor #inbox\n%date %file\n\n"
+ "= %title%cursor #meeting\n%date %file\n\nAttendees: \n"
+ "= @%title%cursor\n%date %file\n\n")
+ howm-keyword-file "~/howm/.howm-keys"
+ howm-history-file "~/howm/.howm-history"
+ howm-menu-file "~/.emacs.d/0000-00-00-000000.txt"
+ howm-file-name-format "%Y%m%dT%H%M%S.txt"
+ howm-keyword-case-fold-search t
+ howm-remember-insertion-format "%s"
+ howm-menu-todo-num 10)
+
+ (defun re/howm-menu-new-frame (&optional arg)
+ "Show the howm menu in a new frame"
+ (interactive "P")
+ (re/open-with-new-frame "HOWM" #'howm-menu))
+
+ (defun re/howm-create-keyword ()
+ "Reads a keyword from the minibuffer and appends it to the keywords file."
+ (interactive)
+ (append-to-file (concat (read-string "New Keyword: ")
+ "\n")
+ nil
+ howm-keyword-file))
+#+END_SRC
+**** Menu config
+#+BEGIN_SRC emacs-lisp
+ ;; add entries in howm-menu (press enter on the text)
+ (defun re/howm-menu-legend ()
+ (cl-labels ((p (text face) (propertize text 'font-lock-face face)))
+ (concat (format "Top %s" howm-menu-todo-num)
+ " "
+ (p "!Deadline" howm-reminder-deadline-face)
+ "/"
+ (p "+ToDo" howm-reminder-todo-face)
+ "/"
+ (p "@Schedule" howm-reminder-schedule-face)
+ "/"
+ (p "~Defer" howm-reminder-defer-face)
+ "/"
+ (p "-Reminder" howm-reminder-normal-face)
+ " Entries:")))
+
+ (with-eval-after-load 'howm
+ (dolist (aldr-additions '(("\\[Mtg\\]" (lambda (&optional dummy) (howm-create 2)))
+ ("\\[Person\\]" (lambda (&optional dummy) (howm-create 3)))))
+ (add-to-list 'action-lock-default-rules aldr-additions t))
+ (add-to-list 'howm-menu-allow 're/howm-menu-legend)
+ ;; add coloring for custom "waiting" state
+ (add-to-list 'howm-reminder-font-lock-keywords
+ `(,(howm-reminder-regexp "[w]") (0 howm-reminder-defer-face prepend))
+ t))
+
+ (dolist (hooks '(after-save-hook howm-mode-hook))
+ (add-hook hooks 'howm-mode-set-buffer-name))
+#+END_SRC
+
** Trashed
Shows the trash file as a dired buffer
#+BEGIN_SRC emacs-lisp
(use-package trashed
:config
(setq trashed-action-confirmer 'y-or-n-p
- trashed-use-header-line t
- trashed-sort-key '("Date deleted" . t)
- trashed-date-format "%Y-%m-%d %H:%M:%S"))
+ trashed-use-header-line t
+ trashed-sort-key '("Date deleted" . t)
+ trashed-date-format "%Y-%m-%d %H:%M:%S"))
#+END_SRC
* Editing
** UNIX/vi-like bindings
"Kill region if active, otherwise kill back one word."
(interactive "p")
(if (use-region-p)
- (kill-region (region-beginning) (region-end))
+ (kill-region (region-beginning) (region-end))
(backward-kill-word arg)))
(keymap-global-set "C-w" #'re/kill-bword-or-region)
Stolen from https://depp.brause.cc/dotemacs"
(interactive "P")
(if (use-region-p)
- (comment-or-uncomment-region (region-beginning) (region-end))
+ (comment-or-uncomment-region (region-beginning) (region-end))
(comment-line arg)))
(keymap-global-set "M-;" #'re/comment-dwim)
Return to initial position after. Arg works on `mark-defun'."
(interactive "P")
(save-excursion (mark-defun arg)
- (comment-region (region-beginning) (region-end))))
+ (comment-region (region-beginning) (region-end))))
(keymap-global-set "C-M-;" #'re/comment-defun)
#+BEGIN_SRC emacs-lisp
;; Tabs
(setq-default indent-tabs-mode t
- tab-width 8
- backward-delete-char-untabify-method nil)
+ tab-width 8
+ backward-delete-char-untabify-method nil)
(advice-add 'indent-to :around
- (lambda (orig-fun column &rest args)
- (when indent-tabs-mode
- (setq column (* tab-width (round column tab-width))))
- (apply orig-fun column args)))
+ (lambda (orig-fun column &rest args)
+ (when indent-tabs-mode
+ (setq column (* tab-width (round column tab-width))))
+ (apply orig-fun column args)))
(dolist (indent-level '(c-basic-offset cperl-indent-level LaTeX-indent-level))
(defvaralias indent-level 'tab-width))
#+BEGIN_SRC emacs-lisp
;; Buffer dealiŋ
(setq-default indicate-empty-lines t
- truncate-lines t
- fill-column 78)
+ truncate-lines t
+ fill-column 78)
(dolist (hook '(text-mode-hook LaTeX-mode-hook))
(add-hook hook #'visual-line-mode))
(interactive "^")
(let ((oldpos (point)))
(if (equal major-mode 'org-mode)
- (org-beginning-of-line)
+ (org-beginning-of-line)
(progn
- (when visual-line-mode (beginning-of-visual-line 1))
- (skip-syntax-forward " " (line-end-position))
- (backward-prefix-chars)))
+ (when visual-line-mode (beginning-of-visual-line 1))
+ (skip-syntax-forward " " (line-end-position))
+ (backward-prefix-chars)))
(and (= oldpos (point))
- (let ((newpos (point)))
- (back-to-indentation)
- (and (= newpos (point)) (beginning-of-line))))))
+ (let ((newpos (point)))
+ (back-to-indentation)
+ (and (= newpos (point)) (beginning-of-line))))))
(keymap-global-set "<remap> <move-beginning-of-line>" #'re/smart-beginning-of-line)
(keymap-set visual-line-mode-map "C-a" #'re/smart-beginning-of-line)
(interactive "^")
(let ((oldpos (point)))
(if (equal major-mode 'org-mode)
- (org-end-of-line)
+ (org-end-of-line)
(when visual-line-mode
- (end-of-visual-line 1)))
+ (end-of-visual-line 1)))
(and (= oldpos (point)) (move-end-of-line nil))))
(keymap-global-set "<remap> <move-end-of-line>" #'re/smart-end-of-line)
(interactive)
(when (use-region-p)
(add-to-history 'search-ring
- (buffer-substring (region-beginning) (region-end)))
+ (buffer-substring (region-beginning) (region-end)))
(deactivate-mark))
(isearch-forward))
(interactive)
(when (use-region-p)
(add-to-history 'search-ring
- (buffer-substring (region-beginning) (region-end)))
+ (buffer-substring (region-beginning) (region-end)))
(deactivate-mark))
(isearch-backward))
Stolen from https://www.masteringemacs.org/article/fixing-mark-commands-transient-mark-mode"
(interactive "P")
(exchange-point-and-mark (if (and transient-mark-mode (not mark-active))
- (not arg)
- arg)))
+ (not arg)
+ arg)))
(keymap-global-set "<remap> <exchange-point-and-mark>" #'re/exchange-point-and-mark-maybe-activate)
(midnight-mode t)
(setq clean-buffer-list-delay-general 1)
(dolist (never-re '("\\` \\*tramp/.*\\'"
- "\\` \\*eshell.*\\'"))
+ "\\` \\*eshell.*\\'"))
(add-to-list 'clean-buffer-list-kill-never-regexps never-re))
(save-place-mode 1)
(recentf-mode 1)
"Renames the current buffer and the file it is visiting."
(interactive)
(let ((name (buffer-name))
- (filename (buffer-file-name)))
+ (filename (buffer-file-name)))
(if (not (and filename (file-exists-p filename)))
- (error "Buffer '%s' is not visiting a file!" name)
+ (error "Buffer '%s' is not visiting a file!" name)
(let ((new-name (read-file-name "New name: " filename)))
- (if (get-buffer new-name)
- (error "A buffer named '%s' already exists!" new-name)
- (rename-file filename new-name 1)
- (rename-buffer new-name)
- (set-visited-file-name new-name)
- (set-buffer-modified-p nil)
- (message "File '%s' successfully renamed to '%s'"
- name
- (file-name-nondirectory new-name)))))))
+ (if (get-buffer new-name)
+ (error "A buffer named '%s' already exists!" new-name)
+ (rename-file filename new-name 1)
+ (rename-buffer new-name)
+ (set-visited-file-name new-name)
+ (set-buffer-modified-p nil)
+ (message "File '%s' successfully renamed to '%s'"
+ name
+ (file-name-nondirectory new-name)))))))
(keymap-global-set "C-x C-r" #'re/rename-current-buffer-file)
(with-temp-buffer
(insert-file-contents file-path)
(if (< line-number 0)
- (progn
- (goto-char (point-max))
- (forward-line line-number))
+ (progn
+ (goto-char (point-max))
+ (forward-line line-number))
(progn
- (goto-char (point-min))
- (forward-line (1- line-number))))
+ (goto-char (point-min))
+ (forward-line (1- line-number))))
(buffer-substring-no-properties (line-beginning-position) (line-end-position))))
(defun re/get-file-modified-time (filepath)
(interactive)
(format-time-string "%Y-%m-%d-%H%M"
- (file-attribute-modification-time (file-attributes filepath))))
+ (file-attribute-modification-time (file-attributes filepath))))
(defun re/filename-inject-mod-time (filepath)
(interactive)
(concat (file-name-sans-extension filepath)
- "_"
- (re/get-file-modified-time filepath)
- (file-name-extension filepath t)))
+ "_"
+ (re/get-file-modified-time filepath)
+ (file-name-extension filepath t)))
(defun re/copy-with-mod-time (&optional filepath)
(interactive)
(let ((filepath (if (eq major-mode 'dired-mode)
- (dired-get-filename t)
- (when (null filepath)
- (read-file-name "File to copy with datestring: "
- default-directory
- nil
- t
- nil)))))
+ (dired-get-filename t)
+ (when (null filepath)
+ (read-file-name "File to copy with datestring: "
+ default-directory
+ nil
+ t
+ nil)))))
(copy-file filepath (re/filename-inject-mod-time filepath ) nil t t t)))
#+END_SRC
* Dired
"In dired mode, visit the file at the cursor in the right/below/left/above window."
(interactive)
(let* ((file-or-dir (dired-get-file-for-visit)) ;; get the file at cursor
- (buffer (find-file-noselect file-or-dir))) ;; load the file into a buffer
+ (buffer (find-file-noselect file-or-dir))) ;; load the file into a buffer
(let ((window ;; figure out the window to use
- (cond ((get-buffer-window buffer (selected-frame)))
- ((window-in-direction 'right)) ;; try window in each direction
- ((window-in-direction 'below)) ;; and default to right
- ((window-in-direction 'left)) ;; if no window found.
- ((window-in-direction 'above))
- (t (split-window (selected-window) nil 'right)))))
+ (cond ((get-buffer-window buffer (selected-frame)))
+ ((window-in-direction 'right)) ;; try window in each direction
+ ((window-in-direction 'below)) ;; and default to right
+ ((window-in-direction 'left)) ;; if no window found.
+ ((window-in-direction 'above))
+ (t (split-window (selected-window) nil 'right)))))
(window--display-buffer buffer window 'window nil)
window)))
"Open dired in a new frame."
(interactive)
(re/open-with-new-frame "DIRED"
- #'(lambda () (interactive) (dired default-directory))))
+ #'(lambda () (interactive) (dired default-directory))))
(keymap-global-set "<f8>" #'re/dired-new-frame)
"Change sort order of dired dir."
(interactive)
(let ((smenu '(("name" . "-Ahl")
- ("mdate" . "-Ahlt")
- ("adate" . "-Ahltu")
- ("size" . "-AhlS")
- ("dir" . "-Ahl --group-directories-first")))
- ssortBy)
+ ("mdate" . "-Ahlt")
+ ("adate" . "-Ahltu")
+ ("size" . "-AhlS")
+ ("dir" . "-Ahl --group-directories-first")))
+ ssortBy)
(setq ssortBy (completing-read "Sort by (default name):"
- smenu
- nil
- t
- nil
- nil
- (caar smenu)))
+ smenu
+ nil
+ t
+ nil
+ nil
+ (caar smenu)))
(dired-sort-other (cdr (assoc ssortBy smenu)))))
(defun re/open-file-external (file)
(interactive)
(let ((process-connection-type nil))
(cond ((eq system-type 'windows-nt)
- (w32-shell-execute "open"
- (replace-regexp-in-string "/" "\\\\" file t t)))
- ((eq system-type 'gnu/linux)
- (start-process "" nil "xdg-open" file))
- (t (error "Unable to automatically open this file")))))
+ (w32-shell-execute "open"
+ (replace-regexp-in-string "/" "\\\\" file t t)))
+ ((eq system-type 'gnu/linux)
+ (start-process "" nil "xdg-open" file))
+ (t (error "Unable to automatically open this file")))))
(defun re/dired-open-externally ()
"Open the file at point in an external program."
dired-kill-when-opening-new-dired-buffer t)
(add-hook 'dired-mode-hook
- (lambda ()
- (progn
- (keymap-set dired-mode-map
- "o"
- #'re/dired-display-direction)
- ;; Rename r,R+M(mv), chmod M>c, compress-to c>z
- (keymap-set dired-mode-map
- "z"
- #'dired-do-compress-to)
- (keymap-set dired-mode-map
- "c"
- #'dired-do-chmod)
- (keymap-set dired-mode-map
- "r"
- #'dired-do-rename)
- (keymap-set dired-mode-map
- "M"
- #'dired-do-rename)
- ;; My add-on defuns
- (keymap-set dired-mode-map
- "s"
- #'re/dired-sort)
- (keymap-set dired-mode-map
- "F"
- #'re/dired-find-marked-files)
- (keymap-set dired-mode-map
- "M-C"
- #'re/copy-with-mod-time)
- (keymap-set dired-mode-map
- "b"
- #'re/dired-open-externally)
- (keymap-set dired-mode-map
- "B"
- #'re/dired-open-marked-externally)
- (dired-hide-details-mode t)
- (hl-line-mode))))
+ (lambda ()
+ (progn
+ (keymap-set dired-mode-map
+ "o"
+ #'re/dired-display-direction)
+ ;; Rename r,R+M(mv), chmod M>c, compress-to c>z
+ (keymap-set dired-mode-map
+ "z"
+ #'dired-do-compress-to)
+ (keymap-set dired-mode-map
+ "c"
+ #'dired-do-chmod)
+ (keymap-set dired-mode-map
+ "r"
+ #'dired-do-rename)
+ (keymap-set dired-mode-map
+ "M"
+ #'dired-do-rename)
+ ;; My add-on defuns
+ (keymap-set dired-mode-map
+ "s"
+ #'re/dired-sort)
+ (keymap-set dired-mode-map
+ "F"
+ #'re/dired-find-marked-files)
+ (keymap-set dired-mode-map
+ "M-C"
+ #'re/copy-with-mod-time)
+ (keymap-set dired-mode-map
+ "b"
+ #'re/dired-open-externally)
+ (keymap-set dired-mode-map
+ "B"
+ #'re/dired-open-marked-externally)
+ (dired-hide-details-mode t)
+ (hl-line-mode))))
#+END_SRC
* Bookmarks
#+BEGIN_SRC emacs-lisp
mouse-autoselect-window -0.25)
(setq-default cursor-type 'hbar
- cursor-in-non-selected-windows nil
- mode-line-format
- '("%e"
- (:eval (propertize " "
- 'face
- (when (buffer-modified-p)
- 'mode-line-highlight)))
- " "
- (:propertize (buffer-file-name "%f" "%b")
- face
- mode-line)
- (vc-mode vc-mode)
- mode-line-format-right-align
- (:eval (number-to-string (line-number-at-pos (point-max))))
- "L @ %I%n %l,%C "))
+ cursor-in-non-selected-windows nil
+ mode-line-format
+ '("%e"
+ (:eval (propertize " "
+ 'face
+ (when (buffer-modified-p)
+ 'mode-line-highlight)))
+ " "
+ (:propertize (buffer-file-name "%f" "%b")
+ face
+ mode-line)
+ (vc-mode vc-mode)
+ mode-line-format-right-align
+ (:eval (number-to-string (line-number-at-pos (point-max))))
+ "L @ %I%n %l,%C "))
(setq prettify-symbols-alist '(("lambda" . 955)
- ("delta" . 120517)
- ("epsilon" . 120518)
- ("->" . 8594)
- ("<=" . 8804)
- (">=" . 8805)))
+ ("delta" . 120517)
+ ("epsilon" . 120518)
+ ("->" . 8594)
+ ("<=" . 8804)
+ (">=" . 8805)))
(global-prettify-symbols-mode t)
#+END_SRC
show-paren-style 'expression)
(setq electric-pair-pairs '((?\" . ?\")
- (?\‘ . ?\’)
- (?\“ . ?\”)
- (?\{ . ?\})
- (?\< . ?\>)))
+ (?\‘ . ?\’)
+ (?\“ . ?\”)
+ (?\{ . ?\})
+ (?\< . ?\>)))
#+END_SRC
* Help
#+BEGIN_SRC emacs-lisp
"Change all groups of blank lines to 1 blank line."
(interactive)
(save-excursion (mark-whole-buffer)
- (replace-regexp "^\n+"
- "\n"
- nil
- (region-beginning)
- (region-end))))
+ (replace-regexp "^\n+"
+ "\n"
+ nil
+ (region-beginning)
+ (region-end))))
;; Cleanup on write
(setq require-final-newline t)
(add-hook 'before-save-hook #'re/flush-extra-lines)
(interactive)
(if (active-minibuffer-window)
(if (minibufferp)
- (minibuffer-keyboard-quit)
- (abort-recursive-edit))
+ (minibuffer-keyboard-quit)
+ (abort-recursive-edit))
(keyboard-quit)))
(keymap-global-set "<remap> <keyboard-quit>" #'re/keyboard-quit) ; Make C-g better
Prompt for url and local dir."
(interactive)
(let* ((url (read-string "Repository URL: "))
- (dir (read-string "Local Dir: " (file-name-base url))))
+ (dir (read-string "Local Dir: " (file-name-base url))))
(vc-git-clone url dir nil)))
(defun re/vc-show-branches (&optional arg)
Remotes as well when arg."
(interactive "P")
(let ((default-directory (if (boundp 'vc-dir-directory)
- vc-dir-directory
- default-directory)))
+ vc-dir-directory
+ default-directory)))
(vc-git-command "*git-branches*"
- nil
- nil
- "branch"
- "--verbose"
- (when arg "--remotes"))
+ nil
+ nil
+ "branch"
+ "--verbose"
+ (when arg "--remotes"))
(pop-to-buffer "*git-branches*")
(goto-char (point-min))
(special-mode)))
With arg, ask for remote, otherwise fetch all."
(interactive "P")
(let* ((default-directory (if (boundp 'vc-dir-directory)
- vc-dir-directory
- default-directory)))
+ vc-dir-directory
+ default-directory)))
(vc-git-command "*vc-fetch*"
- nil
- nil
- "fetch"
- (if arg
- (read-string "Fetch From: " "origin")
- "--all")
- "--verbose")
+ nil
+ nil
+ "fetch"
+ (if arg
+ (read-string "Fetch From: " "origin")
+ "--all")
+ "--verbose")
(pop-to-buffer "*vc-fetch*")
(goto-char (point-min))
(special-mode)))
(setq vc-git-root-log-format
`("%d %h %ai %an: %s"
- ;; The first shy group matches the characters drawn by --graph.
- ;; We use numbered groups because `log-view-message-re' wants the
- ;; revision number to be group 1.
- ,(concat "^\\(?:[*/\\|]+\\)\\(?:[*/\\| ]+\\)?"
- "\\(?2: ([^)]+) \\)?\\(?1:[0-9a-z]+\\) "
- "\\(?4:[0-9]\\{4\\}-[0-9-]\\{4\\}[0-9\s+:-]\\{16\\}\\) "
- "\\(?3:.*?\\):")
- ((1 'log-view-message)
- (2 'change-log-list nil lax)
- (3 'change-log-name)
- (4 'change-log-date))))
+ ;; The first shy group matches the characters drawn by --graph.
+ ;; We use numbered groups because `log-view-message-re' wants the
+ ;; revision number to be group 1.
+ ,(concat "^\\(?:[*/\\|]+\\)\\(?:[*/\\| ]+\\)?"
+ "\\(?2: ([^)]+) \\)?\\(?1:[0-9a-z]+\\) "
+ "\\(?4:[0-9]\\{4\\}-[0-9-]\\{4\\}[0-9\s+:-]\\{16\\}\\) "
+ "\\(?3:.*?\\):")
+ ((1 'log-view-message)
+ (2 'change-log-list nil lax)
+ (3 'change-log-name)
+ (4 'change-log-date))))
(setq backup-directory-alist `((".*" . "~/emacs-backups/"))
backup-by-copying t
(keymap-global-set "C-x v f" #'re/vc-fetch)
(add-hook 'vc-dir-mode-hook
- (lambda ()
- (keymap-set vc-dir-mode-map "b b" #'re/vc-show-branches)
- (keymap-set vc-dir-mode-map "f" #'re/vc-fetch)))
+ (lambda ()
+ (keymap-set vc-dir-mode-map "b b" #'re/vc-show-branches)
+ (keymap-set vc-dir-mode-map "f" #'re/vc-fetch)))
#+END_SRC
* Any Lisp Repl
#+BEGIN_SRC emacs-lisp
Either delete, move forward, or add as many ')' as needed."
(let ((distance (re/sexp-unbalanced-count)))
(cond ((re/sexp-need-paren-p)
- (if (looking-at ")")
- (progn
- (forward-char)
- (re/balance-sexp))
- (insert-char 41 distance)))
- ((re/sexp-drop-paren-p)
- (backward-delete-char distance)))))
+ (if (looking-at ")")
+ (progn
+ (forward-char)
+ (re/balance-sexp))
+ (insert-char 41 distance)))
+ ((re/sexp-drop-paren-p)
+ (backward-delete-char distance)))))
(defmacro re/balance-and-eval-sexp (executor)
"Balance the sexp before point, then call `executor'.
(dolist (hook *re/lisp-mode-hooks*)
(add-hook hook
- (lambda ()
- (when (bound-and-true-p acme-mouse-mode) (acme-mouse-mode -1))
- (sedit-mouse-mode 1)
- (keymap-set lisp-mode-shared-map "C-M-z" #'eval-region)
- (keymap-set lisp-mode-shared-map
- "C-M-S-q"
- #'sedit-auto-prettify-sexp)
- (keymap-set lisp-mode-shared-map
- "]"
- (re/balance-and-eval-sexp #'sedit-auto-prettify-sexp))
- (keymap-set lisp-interaction-mode-map
- "]"
- (re/balance-and-eval-sexp #'eval-print-last-sexp)))))
+ (lambda ()
+ (when (bound-and-true-p acme-mouse-mode) (acme-mouse-mode -1))
+ (sedit-mouse-mode 1)
+ (keymap-set lisp-mode-shared-map "C-M-z" #'eval-region)
+ (keymap-set lisp-mode-shared-map
+ "C-M-S-q"
+ #'sedit-auto-prettify-sexp)
+ (keymap-set lisp-mode-shared-map
+ "]"
+ (re/balance-and-eval-sexp #'sedit-auto-prettify-sexp))
+ (keymap-set lisp-interaction-mode-map
+ "]"
+ (re/balance-and-eval-sexp #'eval-print-last-sexp)))))
#+END_SRC
* IELM
#+BEGIN_SRC emacs-lisp
;; IELM
(add-hook 'ielm-mode-hook
- (lambda ()
- (keymap-set inferior-emacs-lisp-mode-map
- "C-l"
- #'comint-clear-buffer)
- (let ((eval-function #'ielm-send-input))
- (keymap-set inferior-emacs-lisp-mode-map
- ")"
- (re/send-on-close-paren eval-function))
- (keymap-set inferior-emacs-lisp-mode-map
- "]"
- (re/balance-and-eval-sexp eval-function)))))
+ (lambda ()
+ (keymap-set inferior-emacs-lisp-mode-map
+ "C-l"
+ #'comint-clear-buffer)
+ (let ((eval-function #'ielm-send-input))
+ (keymap-set inferior-emacs-lisp-mode-map
+ ")"
+ (re/send-on-close-paren eval-function))
+ (keymap-set inferior-emacs-lisp-mode-map
+ "]"
+ (re/balance-and-eval-sexp eval-function)))))
#+END_SRC
* Eshell
#+BEGIN_SRC emacs-lisp
(keymap-global-set "C-c e" #'eshell)
(add-hook 'eshell-mode-hook
- (lambda ()
- (keymap-set eshell-mode-map "C-d" #'eshell-quit-or-delete-char)
- (let ((eval-function #'eshell-send-input))
- (keymap-set eshell-mode-map
- ")"
- (re/send-on-close-paren eval-function))
- (keymap-set eshell-mode-map
- "]"
- (re/balance-and-eval-sexp eval-function)))))
+ (lambda ()
+ (keymap-set eshell-mode-map "C-d" #'eshell-quit-or-delete-char)
+ (let ((eval-function #'eshell-send-input))
+ (keymap-set eshell-mode-map
+ ")"
+ (re/send-on-close-paren eval-function))
+ (keymap-set eshell-mode-map
+ "]"
+ (re/balance-and-eval-sexp eval-function)))))
(defun eshell-quit-or-delete-char (arg)
"Delete char if at one, quit eshell if on empty prompt.
"Line up argument lists by tabs, not spaces.
Stolen from https://kernel.org/doc/html/v4.10/process/coding-style.html"
(let* ((anchor (c-langelem-pos c-syntactic-element))
- (column (c-langelem-2nd-pos c-syntactic-element))
- (offset (- (1+ column) anchor))
- (steps (floor offset c-basic-offset)))
+ (column (c-langelem-2nd-pos c-syntactic-element))
+ (offset (- (1+ column) anchor))
+ (steps (floor offset c-basic-offset)))
(* (max steps 1) c-basic-offset)))
(add-hook 'c-mode-common-hook
- (lambda ()
- (c-add-style "linux-tabs-only"
- '("linux" (c-offsets-alist
- (arglist-cont-nonempty
- c-lineup-gcc-asm-reg
- re/c-lineup-arglist-tabs-only))))))
+ (lambda ()
+ (c-add-style "linux-tabs-only"
+ '("linux" (c-offsets-alist
+ (arglist-cont-nonempty
+ c-lineup-gcc-asm-reg
+ re/c-lineup-arglist-tabs-only))))))
(add-hook 'c-mode-hook
- (lambda ()
- (setq c-backspace-function 'backward-delete-char)
- (c-set-style "linux-tabs-only")))
+ (lambda ()
+ (setq c-backspace-function 'backward-delete-char)
+ (c-set-style "linux-tabs-only")))
#+END_SRC
* Auto-Revert
#+BEGIN_SRC emacs-lisp