From 1543ac66ba6f829082b745e6a11a9aeb9e8faec7 Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Wed, 23 Mar 2022 09:55:58 -0700 Subject: rename a few more libraries --- emacs/custom/fcuny-conf.el | 48 --------- emacs/custom/fcuny-defuns.el | 40 -------- emacs/custom/fcuny-eshell.el | 231 ----------------------------------------- emacs/custom/fcuny-notmuch.el | 20 ---- emacs/custom/fcuny-prog.el | 131 ------------------------ emacs/custom/fcuny-tramp.el | 15 --- emacs/custom/fcuny-vars.el | 26 ----- emacs/custom/my-conf.el | 53 ++++++++++ emacs/custom/my-defuns.el | 40 ++++++++ emacs/custom/my-eshell.el | 232 ++++++++++++++++++++++++++++++++++++++++++ emacs/custom/my-notmuch.el | 20 ++++ emacs/custom/my-prog.el | 131 ++++++++++++++++++++++++ emacs/custom/my-tramp.el | 15 +++ emacs/custom/my-ui.el | 2 +- emacs/custom/my-vars.el | 26 +++++ 15 files changed, 518 insertions(+), 512 deletions(-) delete mode 100644 emacs/custom/fcuny-conf.el delete mode 100644 emacs/custom/fcuny-defuns.el delete mode 100644 emacs/custom/fcuny-eshell.el delete mode 100644 emacs/custom/fcuny-notmuch.el delete mode 100644 emacs/custom/fcuny-prog.el delete mode 100644 emacs/custom/fcuny-tramp.el delete mode 100644 emacs/custom/fcuny-vars.el create mode 100644 emacs/custom/my-conf.el create mode 100644 emacs/custom/my-defuns.el create mode 100644 emacs/custom/my-eshell.el create mode 100644 emacs/custom/my-notmuch.el create mode 100644 emacs/custom/my-prog.el create mode 100644 emacs/custom/my-tramp.el create mode 100644 emacs/custom/my-vars.el (limited to 'emacs/custom') diff --git a/emacs/custom/fcuny-conf.el b/emacs/custom/fcuny-conf.el deleted file mode 100644 index 7258d9f..0000000 --- a/emacs/custom/fcuny-conf.el +++ /dev/null @@ -1,48 +0,0 @@ -;;; fcuny-conf.el -- setup configuration modes -;;; Commentary: -;;; Code: - -(require 'fcuny-defuns) -(require 'use-package) - -(use-package dockerfile-mode - :ensure t - :mode "Dockerfile[a-zA-Z.-]*\\'") - -(use-package yaml-mode - :ensure t) - -(use-package js-mode - :custom - (json-reformat:indent-width 2) - (js-indent-level 2) - :hook ((json-mode . flyspell-prog-mode))) - -(use-package jq-format - :ensure t) - -(use-package protobuf-mode - :ensure t - :hook ((protobuf-mode . flyspell-prog-mode))) - -(use-package systemd - :ensure t - :hook ((systemd-mode . flyspell-prog-mode) - (systemd-mode . company-mode))) - -(use-package hcl-mode - :ensure t) - -(use-package terraform-mode - :ensure t - :mode (("\\.tf\\'" . terraform-mode)) - :hook (terraform-mode . terraform-format-on-save-mode)) - -(use-package terraform-doc - :ensure t) - -(use-package chef-mode - :ensure t) - -(provide 'fcuny-conf) -;;; fcuny-conf.el ends here diff --git a/emacs/custom/fcuny-defuns.el b/emacs/custom/fcuny-defuns.el deleted file mode 100644 index 0c358ce..0000000 --- a/emacs/custom/fcuny-defuns.el +++ /dev/null @@ -1,40 +0,0 @@ -(defun fcuny/remove-mysql-columns () - "Removes from text. This is useful when I want to drop the column separator from some text coming from a mysql query." - (interactive) - (while (search-forward-regexp "\s?|\s?") - (replace-match " "))) - -(defun fcuny/copy-whole-buffer () - "Selects the buffer and copy it." - (interactive) - (save-excursion - (mark-whole-buffer) - (copy-region-as-kill 1 (buffer-size)))) - -;; from https://karl-voit.at/2014/08/10/bookmarks-with-orgmode/ -(defun fcuny/string-replace (this withthat in) - "replace THIS with WITHTHAT' in the string IN" - (with-temp-buffer - (insert in) - (goto-char (point-min)) - (replace-string this withthat) - (buffer-substring (point-min) (point-max)))) - -(defun fcuny/get-page-title (url) - "Make URL into an org-mode link." - (let ((title)) - (with-current-buffer (url-retrieve-synchronously url) - (goto-char (point-min)) - (re-search-forward "\\([^<]*\\)" nil t 1) - (setq title (match-string 1)) - (goto-char (point-min)) - (re-search-forward "charset=\\([-0-9a-zA-Z]*\\)" nil t 1) - (fcuny/string-replace " " " " - ;;(decode-coding-string title (intern (match-string 1))) - ;; following line fixes charset issues from - ;; previous line: - (decode-coding-string title 'utf-8)) - (concat "[[" url "][" title "]]")))) - - -(provide 'fcuny-defuns) diff --git a/emacs/custom/fcuny-eshell.el b/emacs/custom/fcuny-eshell.el deleted file mode 100644 index 29495ef..0000000 --- a/emacs/custom/fcuny-eshell.el +++ /dev/null @@ -1,231 +0,0 @@ -;;; fcuny-eshell.el --- Configure eshell -;;; Commentary: -;;; Code: - -(require 'use-package) -(require 'magit) - -(require 'eshell) -(require 'esh-mode) -(require 'esh-module) - -(setq eshell-modules-list - '(eshell-alias - eshell-basic - eshell-cmpl - eshell-dirs - eshell-glob - eshell-hist - eshell-ls - eshell-pred - eshell-prompt - eshell-script - eshell-term - eshell-tramp - eshell-unix)) - -(require 'em-alias) -(require 'em-basic) -(require 'em-dirs) -(require 'em-glob) -(require 'em-hist) -(require 'em-smart) -(require 'em-term) -(require 'em-tramp) -(require 'em-prompt) - -(defun fcuny/eshell-mode-setup () - "Configures various aliases for eshell." - (eshell/alias "e" "find-file $1") - (eshell/alias "emacs" "find-file $1") - (eshell/alias "ee" "find-file-other-window $1") - - (eshell/alias "ll" "ls -l") - (eshell/alias "d" "dired $1") - - (eshell/alias "gs" "magit-status") - (eshell/alias "gd" "magit-diff-unstaged") - (eshell/alias "gds" "magit-diff-staged") - - (eshell/alias "rg" "counsel-rg") - - (eshell/alias "cal" "calendar") - - (eshell/alias "agenda" "org-agenda") - - ;; Disable current line highlighting. - (setq-local global-hl-line-mode nil)) - -(defun eshell/gst (&rest args) - "Alias for git-status using magit, with optional ARGS." - (magit-status (pop args) nil) - (eshell/echo)) ;; The echo command suppresses output - -(defun fcuny/eshell--open-or-cd (path) - "Cd to PATH if path is a directory, otherwise open PATH via `find-file'." - (interactive) - (if (file-directory-p path) - (progn - (goto-char (point-max)) - (insert (concat "cd " path)) - (eshell-send-input) - (insert (concat "ls -l")) - (eshell-send-input)) - (find-file path))) - -(defun fcuny/eshell-open-file-at-point () - "Open the file at point in a buffer." - (interactive) - (let ((filename (symbol-name (symbol-at-point)))) - (cond - ((file-readable-p filename) - (fcuny/eshell--open-or-cd filename)) - ((file-readable-p (expand-file-name filename)) - (fcuny/eshell--open-or-cd (expand-file-name filename)))))) - -(defun fcuny/shorten-path (path &optional max-len) - "Return a potentially trimmed-down version of the directory PATH. -Replacing parent directories with their initial characters to try -to get the character length of PATH (sans directory slashes) down -to MAX-LEN." - (let* ((components (split-string (abbreviate-file-name path) "/")) - (host (propertize (system-name) 'face `(:background "#4ba9aa"))) - (max-len (or max-len 30)) - (len (+ (1- (length components)) - (cl-reduce '+ components :key 'length))) - (str "")) - (while (and (> len max-len) - (cdr components)) - (setq str (concat str - (cond ((= 0 (length (car components))) "/") - ((= 1 (length (car components))) - (concat (car components) "/")) - (t - (if (string= "." - (string (elt (car components) 0))) - (concat (substring (car components) 0 2) - "/") - (string (elt (car components) 0) ?/))))) - len (- len (1- (length (car components)))) - components (cdr components))) - (concat host " " str (cl-reduce (lambda (a b) (concat a "/" b)) components)))) - -(defun fcuny/eshell-prompt () - "Sets the prompt for eshell. -If the current path is on a remotehost and starts with `ssh:', -then we replace the prompt with `@' to indicate we're -on a remote host." - (concat - (let ((absolute-path (eshell/pwd))) - (if (string-match "/ssh:\\(.+\\):" absolute-path) - (replace-match (propertize (concat "@" (match-string 1 absolute-path) " ") 'face `(:background "#4ba9aa")) nil nil absolute-path) - (fcuny/shorten-path absolute-path))) - (if (= (user-uid) 0) " # " " $ "))) - -(defun fcuny/eshell-here () - "Opens a new shell in the directory associated with the current buffer's file. -The eshell is renamed to match that directory to make multiple -eshell windows easier." - (interactive) - (let* ((parent (if (buffer-file-name) - (file-name-directory (buffer-file-name)) - default-directory)) - (name (car (last (split-string parent "/" t))))) - (split-window-horizontally) - (other-window 1) - (eshell "new") - (rename-buffer (concat "*eshell: " name "*")) - (insert (concat "ls " "-lh")) - (eshell-send-input))) - -(defun fcuny/eshell-main () - "Create a buffer for eshell." - (eshell "new") - (rename-buffer "*eshell: main session*") - (insert "ls -l") - (eshell-send-input)) - -(defvar-local fcuny/eshell-output-buffer "*Exported eshell output*" - "Name of buffer with the last output of Eshell command.") - -(defvar-local fcuny/eshell-output-delimiter "---" - "Delimiter for successive `prot-eshell-export' outputs.") - -(defun fcuny/eshell--command-prompt-output () - "Capture last command prompt and its output." - (let ((beg (save-excursion - (goto-char (eshell-beginning-of-input)) - (goto-char (point-at-bol))))) - (when (derived-mode-p 'eshell-mode) - (buffer-substring-no-properties beg (eshell-end-of-output))))) - -;; https://gitlab.com/protesilaos/dotfiles/-/blob/master/emacs/.emacs.d/prot-lisp/prot-eshell.el#L114 -(defun fcuny/eshell-export () - "Produce a buffer with output of the last Eshell command. -If `fcuny/eshell-output-buffer' does not exist, create it. Else -append to it, while separating multiple outputs with -`fcuny/eshell-output-delimiter'." - (interactive) - (let ((eshell-output (fcuny/eshell--command-prompt-output))) - (with-current-buffer (get-buffer-create fcuny/eshell-output-buffer) - (goto-char (point-max)) - (unless (eq (point-min) (point-max)) - (insert (format "\n%s\n\n" fcuny/eshell-output-delimiter))) - (goto-char (point-at-bol)) - (insert eshell-output) - (switch-to-buffer-other-window (current-buffer))))) - -;; eshell time and notification -(defvar-local eshell-current-command-start-time nil) - -;; https://www.birkey.co/2021-06-20-why-eshell-part-1.html -(defun fcuny/eshell-current-command-start () - "Capture the time for when the command is started." - (setq eshell-current-command-start-time (current-time))) - -(defun fcuny/eshell-current-command-stop () - "Calculate how long the command took to run." - (when eshell-current-command-start-time - (let ((elapsed-time (float-time - (time-subtract (current-time) - eshell-current-command-start-time)))) - (if (> elapsed-time 5) - (eshell-interactive-print - (format "Finished in: %.0fs\n" elapsed-time))))) - (setq eshell-current-command-start-time nil)) - -(defun fcuny/eshell-current-command-time-track () - "Track how long command takes to run." - (add-hook 'eshell-pre-command-hook #'fcuny/eshell-current-command-start nil t) - (add-hook 'eshell-post-command-hook #'fcuny/eshell-current-command-stop nil t)) - -(use-package eshell - :hook ((eshell-mode . fcuny/eshell-mode-setup) - (eshell-mode . fcuny/eshell-current-command-time-track) - (eshell-mode . eshell-smart-initialize)) - :commands (eshell eshell-command) - :bind (("C-c e h" . fcuny/eshell-here) - ("C-c e e" . fcuny/eshell-export) - ("C-c r" . counsel-esh-history) - :map eshell-mode-map - ("C-o" . fcuny/eshell-open-file-at-point)) - :custom - (eshell-scroll-to-bottom-on-input 'all) - (eshell-error-if-no-glob t) - (eshell-hist-ignoredups t) - (eshell-save-history-on-exit t) - (eshell-cd-on-directory t) - (eshell-prefer-lisp-functions nil) - (eshell-where-to-jump 'begin) - (eshell-review-quick-commands nil) - (eshell-smart-space-goes-to-end t) - (eshell-prompt-function 'fcuny/eshell-prompt) - (tramp-shell-prompt-pattern "^[^$>\n]*[#$%>] *\\(\[[0-9;]*[a-zA-Z] *\\)*") - (eshell-destroy-buffer-when-process-dies t)) - -(use-package eshell-bookmark - :ensure t - :hook (eshell-mode . eshell-bookmark-setup)) - -(provide 'fcuny-eshell) -;;; fcuny-eshell.el ends here diff --git a/emacs/custom/fcuny-notmuch.el b/emacs/custom/fcuny-notmuch.el deleted file mode 100644 index 3334733..0000000 --- a/emacs/custom/fcuny-notmuch.el +++ /dev/null @@ -1,20 +0,0 @@ -;;; fcuny-notmuch.el --- Configures notmuch -;;; Commentary: -;;; Code: - -(require 'use-package) - -(use-package notmuch - :ensure t - :if (executable-find "notmuch") - :hook - (notmuch-message-mode . flyspell-mode) - :custom - (notmuch-show-logo nil) - (notmuch-search-oldest-first nil) - (notmuch-always-prompt-for-sender t) - (notmuch-show-relative-dates t) - (notmuch-archive-tags '("-inbox" "-unread"))) - -(provide 'fcuny-notmuch) -;;; fcuny-notmuch.el ends here diff --git a/emacs/custom/fcuny-prog.el b/emacs/custom/fcuny-prog.el deleted file mode 100644 index 2c4635e..0000000 --- a/emacs/custom/fcuny-prog.el +++ /dev/null @@ -1,131 +0,0 @@ -;;; fcuny-prog.el --- Configures emacs for various programming languages -;;; Commentary: - -;;; Code: - -(require 'fcuny-vars) -(require 'use-package) - -(use-package man - :custom - (Man-notify-method 'aggressive) - (Man-fontify-manpage-flag t)) - -(use-package compile - :ensure nil - :custom - (compilation-scroll-output t) - ;; Skip over warnings and info messages in compilation - (compilation-skip-threshold 2) - ;; Don't freeze when process reads from stdin - (compilation-disable-input t) - ;; Show three lines of context around the current message - (compilation-context-lines 3)) - -(use-package flymake - :ensure nil - :hook ((prog-mode . flymake-mode) - (conf-mode . flymake-mode)) - :bind (:map flymake-mode-map (("C-c ! s" . flymake-start) - ("C-c ! d" . flymake-show-buffer-diagnostics) - ("C-c ! n" . flymake-goto-next-error) - ("C-c ! p" . flymake-goto-prev-error))) - :custom - (elisp-flymake-byte-compile-load-path load-path)) - -;; yasnippet is required to support place holders with eglot -(use-package yasnippet - :ensure t - :hook - ((prog-mode org-mode dap-ui-repl-mode conf-mode) . yas-minor-mode) - :config - (yas-reload-all)) - -(use-package auto-fill - :hook (prog-mode . auto-fill-mode) - :custom - ;; this does not seem to work .. - (comment-fill-column 80) - (comment-auto-fill-only-comments t)) - -(use-package company - :ensure t - :diminish company-mode - :hook (prog-mode . company-mode) - :custom - (company-minimum-prefix-length 2) - (company-tooltip-align-annotations t) - (company-tooltip-limit 12) - (company-idle-delay 1)) - -(use-package lispy - :ensure t - :config - (dolist (hook '(emacs-lisp-mode-hook)) - (add-hook hook #'lispy-mode))) - -(use-package eldoc - :ensure nil - :hook - ((prog-mode conf-mode) . eldoc-mode) - :bind ("C-c C-h" . eldoc)) - -(use-package eglot - :after (yasnippet company) - :commands (eglot eglot-ensure) - :ensure t - :bind (:map eglot-mode-map - ("C-c C-r" . eglot-rename) - ("C-c C-a" . eglot-code-actions)) - :hook ((go-mode . eglot-ensure) - (nix-mode . eglot-ensure) - (eglot-managed-mode-hook . turn-on-eldoc-mode)) - :init - (setq-default eglot-workspace-configuration - ;; List of settings for gopls: - ;; https://github.com/golang/tools/blob/master/gopls/doc/settings.md - '((:gopls . - ((staticcheck . t) - (matcher . "CaseSensitive") - (usePlaceholders . t)))))) - -(use-package sh-script - :mode ("bashrc" . sh-mode) - :hook (after-save . executable-make-buffer-file-executable-if-script-p) - :config - (setq-default sh-indentation 2 - sh-basic-offset 2)) - -(use-package python - :mode (("\\.py$" . python-mode)) - :commands python-mode - :hook ((python-mode . eldoc-mode)) - :custom (python-indent-offset 2)) - -(use-package make-mode - :config - (add-hook 'makefile-mode-hook (lambda () (setq-local tab-width 2)))) - -(use-package go-mode - :after (eglot) - :ensure t - :hook ((before-save . gofmt-before-save)) - :custom - (tab-width 4)) - -(use-package gotest - :after (go-mode) - :ensure t) - -(use-package lisp-mode - :bind - (("C-c C-e" . eval-buffer) - ("C-c C-r" . eval-region))) - -(use-package nix-mode - :ensure t - :mode "\\.nix\\'" - :hook ((before-save . nix-format-before-save))) - -(provide 'fcuny-prog) -;;; fcuny-prog.el ends here diff --git a/emacs/custom/fcuny-tramp.el b/emacs/custom/fcuny-tramp.el deleted file mode 100644 index 68bacf7..0000000 --- a/emacs/custom/fcuny-tramp.el +++ /dev/null @@ -1,15 +0,0 @@ -;;; fcuny-tramp.el --- Configure tramp -;;; Commentary: -;;; Code: - -(require 'use-package) - -(use-package tramp - :custom - (tramp-default-method "ssh") - (tramp-histfile-override t) - (tramp-ssh-controlmaster-options - "-o ControlMaster=auto -o ControlPath='tramp.%%C'")) - -(provide 'fcuny-tramp) -;;; fcuny-tramp.el ends here diff --git a/emacs/custom/fcuny-vars.el b/emacs/custom/fcuny-vars.el deleted file mode 100644 index 632e4c5..0000000 --- a/emacs/custom/fcuny-vars.el +++ /dev/null @@ -1,26 +0,0 @@ -;;; fcuny-vars.el --- Set a number of variables -;;; Commentary: -;;; Code: - -(defvar fcuny/path-emacs-var (expand-file-name "var" user-emacs-directory) - "Path to some files for Emacs.") - -(defvar fcuny/path-emacs-etc (expand-file-name "etc" user-emacs-directory) - "Path to some files for Emacs.") - -(defvar fcuny/custom-settings (expand-file-name "emacs-custom.el" fcuny/path-emacs-var) - "Path to Emacs custom variables.") - -(defvar fcuny/path-emacs-elpa (expand-file-name "elpa" fcuny/path-emacs-var) - "Path to elpa's local files.") - -(defvar fcuny/path-workspace (expand-file-name "workspace" (getenv "HOME")) - "Path to the workspace.") - -(defvar fcuny/org-directory - (if (memq window-system '(mac ns)) - (expand-file-name "~/workspace/notebooks/") - (expand-file-name "~/documents/notes/"))) - -(provide 'fcuny-vars) -;;; fcuny-vars.el ends here diff --git a/emacs/custom/my-conf.el b/emacs/custom/my-conf.el new file mode 100644 index 0000000..3cb7234 --- /dev/null +++ b/emacs/custom/my-conf.el @@ -0,0 +1,53 @@ +;;; my-conf.el --- Configure modes related to configuration files -*- lexical-binding: t -*- + +;;; Commentary: +;; Provides configuration for modes that are related to configuration +;; files. + +;;; Code: + +;; (require 'fcuny-defuns) +(require 'use-package) + +(use-package dockerfile-mode + :ensure t + :custom + (dockerfile-use-sudo t)) + +(use-package yaml-mode + :ensure t) + +(use-package js-mode + :custom + (json-reformat:indent-width 2) + (js-indent-level 2) + :hook ((json-mode . flyspell-prog-mode))) + +(use-package jq-format + :ensure t) + +(use-package protobuf-mode + :ensure t + :hook ((protobuf-mode . flyspell-prog-mode))) + +(use-package systemd + :ensure t + :hook ((systemd-mode . flyspell-prog-mode) + (systemd-mode . company-mode))) + +(use-package hcl-mode + :ensure t) + +(use-package terraform-mode + :ensure t + :mode (("\\.tf\\'" . terraform-mode)) + :hook (terraform-mode . terraform-format-on-save-mode)) + +(use-package terraform-doc + :ensure t) + +(use-package chef-mode + :ensure t) + +(provide 'my-conf) +;;; my-conf.el ends here diff --git a/emacs/custom/my-defuns.el b/emacs/custom/my-defuns.el new file mode 100644 index 0000000..dc035c4 --- /dev/null +++ b/emacs/custom/my-defuns.el @@ -0,0 +1,40 @@ +(defun fcuny/remove-mysql-columns () + "Removes from text. This is useful when I want to drop the column separator from some text coming from a mysql query." + (interactive) + (while (search-forward-regexp "\s?|\s?") + (replace-match " "))) + +(defun fcuny/copy-whole-buffer () + "Selects the buffer and copy it." + (interactive) + (save-excursion + (mark-whole-buffer) + (copy-region-as-kill 1 (buffer-size)))) + +;; from https://karl-voit.at/2014/08/10/bookmarks-with-orgmode/ +(defun fcuny/string-replace (this withthat in) + "replace THIS with WITHTHAT' in the string IN" + (with-temp-buffer + (insert in) + (goto-char (point-min)) + (replace-string this withthat) + (buffer-substring (point-min) (point-max)))) + +(defun fcuny/get-page-title (url) + "Make URL into an org-mode link." + (let ((title)) + (with-current-buffer (url-retrieve-synchronously url) + (goto-char (point-min)) + (re-search-forward "\\([^<]*\\)" nil t 1) + (setq title (match-string 1)) + (goto-char (point-min)) + (re-search-forward "charset=\\([-0-9a-zA-Z]*\\)" nil t 1) + (fcuny/string-replace " " " " + ;;(decode-coding-string title (intern (match-string 1))) + ;; following line fixes charset issues from + ;; previous line: + (decode-coding-string title 'utf-8)) + (concat "[[" url "][" title "]]")))) + + +(provide 'my-defuns) diff --git a/emacs/custom/my-eshell.el b/emacs/custom/my-eshell.el new file mode 100644 index 0000000..a6b2cfc --- /dev/null +++ b/emacs/custom/my-eshell.el @@ -0,0 +1,232 @@ +;;; my-eshell.el --- Configure eshell +;;; Commentary: +;;; Code: +(eval-when-compile + (require 'use-package) ) + +(require 'magit) + +(require 'eshell) +(require 'esh-mode) +(require 'esh-module) + +(setq eshell-modules-list + '(eshell-alias + eshell-basic + eshell-cmpl + eshell-dirs + eshell-glob + eshell-hist + eshell-ls + eshell-pred + eshell-prompt + eshell-script + eshell-term + eshell-tramp + eshell-unix)) + +(require 'em-alias) +(require 'em-basic) +(require 'em-dirs) +(require 'em-glob) +(require 'em-hist) +(require 'em-smart) +(require 'em-term) +(require 'em-tramp) +(require 'em-prompt) + +(defun fcuny/eshell-mode-setup () + "Configures various aliases for eshell." + (eshell/alias "e" "find-file $1") + (eshell/alias "emacs" "find-file $1") + (eshell/alias "ee" "find-file-other-window $1") + + (eshell/alias "ll" "ls -l") + (eshell/alias "d" "dired $1") + + (eshell/alias "gs" "magit-status") + (eshell/alias "gd" "magit-diff-unstaged") + (eshell/alias "gds" "magit-diff-staged") + + (eshell/alias "rg" "counsel-rg") + + (eshell/alias "cal" "calendar") + + (eshell/alias "agenda" "org-agenda") + + ;; Disable current line highlighting. + (setq-local global-hl-line-mode nil)) + +(defun eshell/gst (&rest args) + "Alias for git-status using magit, with optional ARGS." + (magit-status (pop args) nil) + (eshell/echo)) ;; The echo command suppresses output + +(defun fcuny/eshell--open-or-cd (path) + "Cd to PATH if path is a directory, otherwise open PATH via `find-file'." + (interactive) + (if (file-directory-p path) + (progn + (goto-char (point-max)) + (insert (concat "cd " path)) + (eshell-send-input) + (insert (concat "ls -l")) + (eshell-send-input)) + (find-file path))) + +(defun fcuny/eshell-open-file-at-point () + "Open the file at point in a buffer." + (interactive) + (let ((filename (symbol-name (symbol-at-point)))) + (cond + ((file-readable-p filename) + (fcuny/eshell--open-or-cd filename)) + ((file-readable-p (expand-file-name filename)) + (fcuny/eshell--open-or-cd (expand-file-name filename)))))) + +(defun fcuny/shorten-path (path &optional max-len) + "Return a potentially trimmed-down version of the directory PATH. +Replacing parent directories with their initial characters to try +to get the character length of PATH (sans directory slashes) down +to MAX-LEN." + (let* ((components (split-string (abbreviate-file-name path) "/")) + (host (propertize (system-name) 'face `(:background "#4ba9aa"))) + (max-len (or max-len 30)) + (len (+ (1- (length components)) + (cl-reduce '+ components :key 'length))) + (str "")) + (while (and (> len max-len) + (cdr components)) + (setq str (concat str + (cond ((= 0 (length (car components))) "/") + ((= 1 (length (car components))) + (concat (car components) "/")) + (t + (if (string= "." + (string (elt (car components) 0))) + (concat (substring (car components) 0 2) + "/") + (string (elt (car components) 0) ?/))))) + len (- len (1- (length (car components)))) + components (cdr components))) + (concat host " " str (cl-reduce (lambda (a b) (concat a "/" b)) components)))) + +(defun fcuny/eshell-prompt () + "Sets the prompt for eshell. +If the current path is on a remotehost and starts with `ssh:', +then we replace the prompt with `@' to indicate we're +on a remote host." + (concat + (let ((absolute-path (eshell/pwd))) + (if (string-match "/ssh:\\(.+\\):" absolute-path) + (replace-match (propertize (concat "@" (match-string 1 absolute-path) " ") 'face `(:background "#4ba9aa")) nil nil absolute-path) + (fcuny/shorten-path absolute-path))) + (if (= (user-uid) 0) " # " " $ "))) + +(defun fcuny/eshell-here () + "Opens a new shell in the directory associated with the current buffer's file. +The eshell is renamed to match that directory to make multiple +eshell windows easier." + (interactive) + (let* ((parent (if (buffer-file-name) + (file-name-directory (buffer-file-name)) + default-directory)) + (name (car (last (split-string parent "/" t))))) + (split-window-horizontally) + (other-window 1) + (eshell "new") + (rename-buffer (concat "*eshell: " name "*")) + (insert (concat "ls " "-lh")) + (eshell-send-input))) + +(defun fcuny/eshell-main () + "Create a buffer for eshell." + (eshell "new") + (rename-buffer "*eshell: main session*") + (insert "ls -l") + (eshell-send-input)) + +(defvar-local fcuny/eshell-output-buffer "*Exported eshell output*" + "Name of buffer with the last output of Eshell command.") + +(defvar-local fcuny/eshell-output-delimiter "---" + "Delimiter for successive `prot-eshell-export' outputs.") + +(defun fcuny/eshell--command-prompt-output () + "Capture last command prompt and its output." + (let ((beg (save-excursion + (goto-char (eshell-beginning-of-input)) + (goto-char (point-at-bol))))) + (when (derived-mode-p 'eshell-mode) + (buffer-substring-no-properties beg (eshell-end-of-output))))) + +;; https://gitlab.com/protesilaos/dotfiles/-/blob/master/emacs/.emacs.d/prot-lisp/prot-eshell.el#L114 +(defun fcuny/eshell-export () + "Produce a buffer with output of the last Eshell command. +If `fcuny/eshell-output-buffer' does not exist, create it. Else +append to it, while separating multiple outputs with +`fcuny/eshell-output-delimiter'." + (interactive) + (let ((eshell-output (fcuny/eshell--command-prompt-output))) + (with-current-buffer (get-buffer-create fcuny/eshell-output-buffer) + (goto-char (point-max)) + (unless (eq (point-min) (point-max)) + (insert (format "\n%s\n\n" fcuny/eshell-output-delimiter))) + (goto-char (point-at-bol)) + (insert eshell-output) + (switch-to-buffer-other-window (current-buffer))))) + +;; eshell time and notification +(defvar-local eshell-current-command-start-time nil) + +;; https://www.birkey.co/2021-06-20-why-eshell-part-1.html +(defun fcuny/eshell-current-command-start () + "Capture the time for when the command is started." + (setq eshell-current-command-start-time (current-time))) + +(defun fcuny/eshell-current-command-stop () + "Calculate how long the command took to run." + (when eshell-current-command-start-time + (let ((elapsed-time (float-time + (time-subtract (current-time) + eshell-current-command-start-time)))) + (if (> elapsed-time 5) + (eshell-interactive-print + (format "Finished in: %.0fs\n" elapsed-time))))) + (setq eshell-current-command-start-time nil)) + +(defun fcuny/eshell-current-command-time-track () + "Track how long command takes to run." + (add-hook 'eshell-pre-command-hook #'fcuny/eshell-current-command-start nil t) + (add-hook 'eshell-post-command-hook #'fcuny/eshell-current-command-stop nil t)) + +(use-package eshell + :hook ((eshell-mode . fcuny/eshell-mode-setup) + (eshell-mode . fcuny/eshell-current-command-time-track) + (eshell-mode . eshell-smart-initialize)) + :commands (eshell eshell-command) + :bind (("C-c e h" . fcuny/eshell-here) + ("C-c e e" . fcuny/eshell-export) + ("C-c r" . counsel-esh-history) + :map eshell-mode-map + ("C-o" . fcuny/eshell-open-file-at-point)) + :custom + (eshell-scroll-to-bottom-on-input 'all) + (eshell-error-if-no-glob t) + (eshell-hist-ignoredups t) + (eshell-save-history-on-exit t) + (eshell-cd-on-directory t) + (eshell-prefer-lisp-functions nil) + (eshell-where-to-jump 'begin) + (eshell-review-quick-commands nil) + (eshell-smart-space-goes-to-end t) + (eshell-prompt-function 'fcuny/eshell-prompt) + (tramp-shell-prompt-pattern "^[^$>\n]*[#$%>] *\\(\[[0-9;]*[a-zA-Z] *\\)*") + (eshell-destroy-buffer-when-process-dies t)) + +(use-package eshell-bookmark + :ensure t + :hook (eshell-mode . eshell-bookmark-setup)) + +(provide 'my-eshell) +;;; my-eshell.el ends here diff --git a/emacs/custom/my-notmuch.el b/emacs/custom/my-notmuch.el new file mode 100644 index 0000000..b009f9e --- /dev/null +++ b/emacs/custom/my-notmuch.el @@ -0,0 +1,20 @@ +;;; my-notmuch.el --- Configures notmuch +;;; Commentary: +;;; Code: + +(require 'use-package) + +(use-package notmuch + :ensure t + :if (executable-find "notmuch") + :hook + (notmuch-message-mode . flyspell-mode) + :custom + (notmuch-show-logo nil) + (notmuch-search-oldest-first nil) + (notmuch-always-prompt-for-sender t) + (notmuch-show-relative-dates t) + (notmuch-archive-tags '("-inbox" "-unread"))) + +(provide 'my-notmuch) +;;; my-notmuch.el ends here diff --git a/emacs/custom/my-prog.el b/emacs/custom/my-prog.el new file mode 100644 index 0000000..ce41935 --- /dev/null +++ b/emacs/custom/my-prog.el @@ -0,0 +1,131 @@ +;;; my-prog.el --- Configures emacs for various programming languages +;;; Commentary: + +;;; Code: + +;; (require 'fcuny-vars) +(require 'use-package) + +(use-package man + :custom + (Man-notify-method 'aggressive) + (Man-fontify-manpage-flag t)) + +(use-package compile + :ensure nil + :custom + (compilation-scroll-output t) + ;; Skip over warnings and info messages in compilation + (compilation-skip-threshold 2) + ;; Don't freeze when process reads from stdin + (compilation-disable-input t) + ;; Show three lines of context around the current message + (compilation-context-lines 3)) + +(use-package flymake + :ensure nil + :hook ((prog-mode . flymake-mode) + (conf-mode . flymake-mode)) + :bind (:map flymake-mode-map (("C-c ! s" . flymake-start) + ("C-c ! d" . flymake-show-buffer-diagnostics) + ("C-c ! n" . flymake-goto-next-error) + ("C-c ! p" . flymake-goto-prev-error))) + :custom + (elisp-flymake-byte-compile-load-path load-path)) + +;; yasnippet is required to support place holders with eglot +(use-package yasnippet + :ensure t + :hook + ((prog-mode org-mode dap-ui-repl-mode conf-mode) . yas-minor-mode) + :config + (yas-reload-all)) + +(use-package auto-fill + :hook (prog-mode . auto-fill-mode) + :custom + ;; this does not seem to work .. + (comment-fill-column 80) + (comment-auto-fill-only-comments t)) + +(use-package company + :ensure t + :diminish company-mode + :hook (prog-mode . company-mode) + :custom + (company-minimum-prefix-length 2) + (company-tooltip-align-annotations t) + (company-tooltip-limit 12) + (company-idle-delay 1)) + +(use-package lispy + :ensure t + :config + (dolist (hook '(emacs-lisp-mode-hook)) + (add-hook hook #'lispy-mode))) + +(use-package eldoc + :ensure nil + :hook + ((prog-mode conf-mode) . eldoc-mode) + :bind ("C-c C-h" . eldoc)) + +(use-package eglot + :after (yasnippet company) + :commands (eglot eglot-ensure) + :ensure t + :bind (:map eglot-mode-map + ("C-c C-r" . eglot-rename) + ("C-c C-a" . eglot-code-actions)) + :hook ((go-mode . eglot-ensure) + (nix-mode . eglot-ensure) + (eglot-managed-mode-hook . turn-on-eldoc-mode)) + :init + (setq-default eglot-workspace-configuration + ;; List of settings for gopls: + ;; https://github.com/golang/tools/blob/master/gopls/doc/settings.md + '((:gopls . + ((staticcheck . t) + (matcher . "CaseSensitive") + (usePlaceholders . t)))))) + +(use-package sh-script + :mode ("bashrc" . sh-mode) + :hook (after-save . executable-make-buffer-file-executable-if-script-p) + :config + (setq-default sh-indentation 2 + sh-basic-offset 2)) + +(use-package python + :mode (("\\.py$" . python-mode)) + :commands python-mode + :hook ((python-mode . eldoc-mode)) + :custom (python-indent-offset 2)) + +(use-package make-mode + :config + (add-hook 'makefile-mode-hook (lambda () (setq-local tab-width 2)))) + +(use-package go-mode + :after (eglot) + :ensure t + :hook ((before-save . gofmt-before-save)) + :custom + (tab-width 4)) + +(use-package gotest + :after (go-mode) + :ensure t) + +(use-package lisp-mode + :bind + (("C-c C-e" . eval-buffer) + ("C-c C-r" . eval-region))) + +(use-package nix-mode + :ensure t + :mode "\\.nix\\'" + :hook ((before-save . nix-format-before-save))) + +(provide 'my-prog) +;;; my-prog.el ends here diff --git a/emacs/custom/my-tramp.el b/emacs/custom/my-tramp.el new file mode 100644 index 0000000..9854dab --- /dev/null +++ b/emacs/custom/my-tramp.el @@ -0,0 +1,15 @@ +;;; my-tramp.el --- Configure tramp +;;; Commentary: +;;; Code: + +(require 'use-package) + +(use-package tramp + :custom + (tramp-default-method "ssh") + (tramp-histfile-override t) + (tramp-ssh-controlmaster-options + "-o ControlMaster=auto -o ControlPath='tramp.%%C'")) + +(provide 'my-tramp) +;;; my-tramp.el ends here diff --git a/emacs/custom/my-ui.el b/emacs/custom/my-ui.el index a0473e6..32bf802 100644 --- a/emacs/custom/my-ui.el +++ b/emacs/custom/my-ui.el @@ -1,4 +1,4 @@ -;;;my-ui -- configure UI elements +;;; my-ui.el --- configure UI elements ;;; Commentary: ;;; Code: diff --git a/emacs/custom/my-vars.el b/emacs/custom/my-vars.el new file mode 100644 index 0000000..03b9fa0 --- /dev/null +++ b/emacs/custom/my-vars.el @@ -0,0 +1,26 @@ +;;; my-vars.el --- Set a number of variables +;;; Commentary: +;;; Code: + +(defvar fcuny/path-emacs-var (expand-file-name "var" user-emacs-directory) + "Path to some files for Emacs.") + +(defvar fcuny/path-emacs-etc (expand-file-name "etc" user-emacs-directory) + "Path to some files for Emacs.") + +(defvar fcuny/custom-settings (expand-file-name "emacs-custom.el" fcuny/path-emacs-var) + "Path to Emacs custom variables.") + +(defvar fcuny/path-emacs-elpa (expand-file-name "elpa" fcuny/path-emacs-var) + "Path to elpa's local files.") + +(defvar fcuny/path-workspace (expand-file-name "workspace" (getenv "HOME")) + "Path to the workspace.") + +(defvar fcuny/org-directory + (if (memq window-system '(mac ns)) + (expand-file-name "~/workspace/notebooks/") + (expand-file-name "~/documents/notes/"))) + +(provide 'my-vars) +;;; my-vars.el ends here -- cgit 1.4.1