summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--emacs/custom/my-conf.el1
-rw-r--r--emacs/custom/my-eshell.el120
-rw-r--r--emacs/custom/my-org.el65
-rw-r--r--emacs/custom/my-prog.el1
-rw-r--r--emacs/elisp/my-buffers.el26
-rw-r--r--emacs/elisp/my-clipboard.el24
-rw-r--r--emacs/elisp/my-git-extra.el42
-rw-r--r--emacs/init.el6
-rw-r--r--emacs/lisp/fcuny-commands.el72
9 files changed, 145 insertions, 212 deletions
diff --git a/emacs/custom/my-conf.el b/emacs/custom/my-conf.el
index 3cb7234..924f90f 100644
--- a/emacs/custom/my-conf.el
+++ b/emacs/custom/my-conf.el
@@ -6,7 +6,6 @@
 
 ;;; Code:
 
-;; (require 'fcuny-defuns)
 (require 'use-package)
 
 (use-package dockerfile-mode
diff --git a/emacs/custom/my-eshell.el b/emacs/custom/my-eshell.el
index a6b2cfc..8852489 100644
--- a/emacs/custom/my-eshell.el
+++ b/emacs/custom/my-eshell.el
@@ -1,9 +1,10 @@
 ;;; my-eshell.el --- Configure eshell
 ;;; Commentary:
+
 ;;; Code:
-(eval-when-compile
-  (require 'use-package)  )
 
+(require 'use-package)
+(require 'cl-seq)
 (require 'magit)
 
 (require 'eshell)
@@ -35,34 +36,21 @@
 (require 'em-tramp)
 (require 'em-prompt)
 
-(defun fcuny/eshell-mode-setup ()
+(defun my/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"))
 
-  (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)
+(defun my/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)
@@ -74,56 +62,17 @@
         (eshell-send-input))
     (find-file path)))
 
-(defun fcuny/eshell-open-file-at-point ()
+(defun my/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))
+      (my/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 `@<hostname>' 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 ()
+      (my/eshell--open-or-cd (expand-file-name filename))))))
+
+(defun my/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."
@@ -139,20 +88,13 @@ eshell windows easier."
     (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*"
+(defvar-local my/eshell-output-buffer "*Exported eshell output*"
   "Name of buffer with the last output of Eshell command.")
 
-(defvar-local fcuny/eshell-output-delimiter "---"
+(defvar-local my/eshell-output-delimiter "---"
   "Delimiter for successive `prot-eshell-export' outputs.")
 
-(defun fcuny/eshell--command-prompt-output ()
+(defun my/eshell--command-prompt-output ()
   "Capture last command prompt and its output."
   (let ((beg (save-excursion
                (goto-char (eshell-beginning-of-input))
@@ -161,17 +103,17 @@ eshell windows easier."
     (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 ()
+(defun my/eshell-export ()
   "Produce a buffer with output of the last Eshell command.
-If `fcuny/eshell-output-buffer' does not exist, create it.  Else
+If `my/eshell-output-buffer' does not exist, create it.  Else
 append to it, while separating multiple outputs with
-`fcuny/eshell-output-delimiter'."
+`my/eshell-output-delimiter'."
   (interactive)
-  (let ((eshell-output (fcuny/eshell--command-prompt-output)))
-    (with-current-buffer (get-buffer-create fcuny/eshell-output-buffer)
+  (let ((eshell-output (my/eshell--command-prompt-output)))
+    (with-current-buffer (get-buffer-create my/eshell-output-buffer)
       (goto-char (point-max))
       (unless (eq (point-min) (point-max))
-        (insert (format "\n%s\n\n" fcuny/eshell-output-delimiter)))
+        (insert (format "\n%s\n\n" my/eshell-output-delimiter)))
       (goto-char (point-at-bol))
       (insert eshell-output)
       (switch-to-buffer-other-window (current-buffer)))))
@@ -180,11 +122,11 @@ append to it, while separating multiple outputs with
 (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 ()
+(defun my/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 ()
+(defun my/eshell-current-command-stop ()
   "Calculate how long the command took to run."
   (when eshell-current-command-start-time
     (let ((elapsed-time (float-time
@@ -195,21 +137,21 @@ append to it, while separating multiple outputs with
 	   (format "Finished in: %.0fs\n" elapsed-time)))))
   (setq eshell-current-command-start-time nil))
 
-(defun fcuny/eshell-current-command-time-track ()
+(defun my/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))
+  (add-hook 'eshell-pre-command-hook #'my/eshell-current-command-start nil t)
+  (add-hook 'eshell-post-command-hook #'my/eshell-current-command-stop nil t))
 
 (use-package eshell
-  :hook ((eshell-mode . fcuny/eshell-mode-setup)
-         (eshell-mode . fcuny/eshell-current-command-time-track)
+  :hook ((eshell-mode . my/eshell-mode-setup)
+         (eshell-mode . my/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)
+  :bind (("C-c e h" . my/eshell-here)
+         ("C-c e e" . my/eshell-export)
          ("C-c r"   . counsel-esh-history)
          :map eshell-mode-map
-         ("C-o" . fcuny/eshell-open-file-at-point))
+         ("C-o" . my/eshell-open-file-at-point))
   :custom
   (eshell-scroll-to-bottom-on-input 'all)
   (eshell-error-if-no-glob t)
@@ -220,7 +162,7 @@ append to it, while separating multiple outputs with
   (eshell-where-to-jump 'begin)
   (eshell-review-quick-commands nil)
   (eshell-smart-space-goes-to-end t)
-  (eshell-prompt-function 'fcuny/eshell-prompt)
+  (eshell-prompt-function 'my/eshell-prompt)
   (tramp-shell-prompt-pattern "^[^$>\n]*[#$%>] *\\(\[[0-9;]*[a-zA-Z] *\\)*")
   (eshell-destroy-buffer-when-process-dies t))
 
diff --git a/emacs/custom/my-org.el b/emacs/custom/my-org.el
index 1c68600..81f7a07 100644
--- a/emacs/custom/my-org.el
+++ b/emacs/custom/my-org.el
@@ -2,10 +2,30 @@
 ;;; Commentary:
 ;;; Code:
 
-;; (require 'fcuny-vars)
-;; (require 'fcuny-clipboard)
-
 (require 'use-package)
+(require 's)
+
+(defvar my/org-directory
+  (if (memq window-system '(mac ns))
+      (expand-file-name "~/workspace/notebooks/")
+    (expand-file-name "~/documents/notes/")))
+
+(defun my/clipboard-get-contents ()
+  "Return the contents of the system clipboard as a string."
+  (condition-case nil
+      (cond
+       ((fboundp 'ns-get-pasteboard)
+        (ns-get-pasteboard))
+       ((and (featurep 'mac)
+             (fboundp 'gui-get-selection))
+        (gui-get-selection 'CLIPBOARD 'NSStringPboardType))
+       ((and (featurep 'mac)
+             (fboundp 'x-get-selection))
+        (x-get-selection 'CLIPBOARD 'NSStringPboardType))
+       ((fboundp 'gui-get-selection)
+        (gui-get-selection 'CLIPBOARD (or x-select-request-type 'UTF8_STRING)))
+       (t
+        (error "Clipboard support not available")))))
 
 (use-package org-ml
   :ensure t)
@@ -42,7 +62,7 @@
                                load-language-list)
 
   :custom
-  ;; (org-directory fcuny/org-directory)
+  (org-directory my/org-directory)
   ;; hide emphasis markup
   (org-hide-emphasis-markers t)
 
@@ -98,8 +118,7 @@
 
   ;; entries
   (org-blank-before-new-entry nil)
-  (org-blank-before-new-entry (quote ((heading . nil)
-				                      (plain-list-item . nil))))
+  (org-blank-before-new-entry (quote ((heading . nil) (plain-list-item . nil))))
 
   ;; see https://github.com/abo-abo/swiper/issues/986
   (org-goto-interface 'outline-path-completion)
@@ -138,26 +157,26 @@
                         ((org-agenda-overriding-header "Not yet started")
                          (org-agenda-skip-function '(org-agenda-skip-entry-if 'deadline 'scheduled))))))))
 
-;; (defun fcuny/org-capture/link ()
-;;   "Make a TODO entry with a link in clipboard.
-;; The page title is used as an entry heading."
-;;   (let* ((url-string (s-trim (fcuny/clipboard-get-contents)))
-;;          (pdf (string-suffix-p "pdf" url-string)))
-;;     (unless pdf
-;;       (let ((page-title (org-web-tools--html-title (org-web-tools--get-url url-string))))
-;;         (concat "* "
-;;                 page-title
-;;                 "\t%^g"
-;;                 "\n:PROPERTIES:\n:CREATED: %T\n:URL: "
-;;                 url-string
-;;                 "\n:END:\n%?")))))
-
 (use-package org-web-tools
   :ensure t)
 
 (use-package org-capture
   :ensure nil
-  :after (org)
+  :after (org org-web-tools)
+  :preface
+  (defun my/org-capture-link ()
+  "Make a TODO entry with a link in clipboard.
+The page title is used as an entry heading."
+  (let* ((url-string (s-trim (my/clipboard-get-contents)))
+         (pdf (string-suffix-p "pdf" url-string)))
+    (unless pdf
+      (let ((page-title (org-web-tools--html-title (org-web-tools--get-url url-string))))
+        (concat "* "
+                page-title
+                "\t%^g"
+                "\n:PROPERTIES:\n:CREATED: %T\n:URL: "
+                url-string
+                "\n:END:\n%?")))))
   :custom
   (org-capture-templates
    `(("t" "Todo" entry (file "inbox.org")
@@ -166,8 +185,8 @@
      ("n" "Note" entry (file "notes.org")
       "* %?\n:PROPERTIES:\n:CREATED: %T\n:END:\n")
 
-     ;; ("l" "Bookmark" entry (file "bookmarks.org")
-     ;;  (function fcuny/org-capture/link))
+     ("l" "Bookmark" entry (file "bookmarks.org")
+      (function my/org-capture-link))
 
      ("j" "Journal" entry
       (file+olp+datetree "journal.org")
diff --git a/emacs/custom/my-prog.el b/emacs/custom/my-prog.el
index ce41935..8994060 100644
--- a/emacs/custom/my-prog.el
+++ b/emacs/custom/my-prog.el
@@ -3,7 +3,6 @@
 
 ;;; Code:
 
-;; (require 'fcuny-vars)
 (require 'use-package)
 
 (use-package man
diff --git a/emacs/elisp/my-buffers.el b/emacs/elisp/my-buffers.el
index d5c07c5..8c03905 100644
--- a/emacs/elisp/my-buffers.el
+++ b/emacs/elisp/my-buffers.el
@@ -9,5 +9,31 @@
     (mark-whole-buffer)
     (copy-region-as-kill 1 (buffer-size))))
 
+(defun my/rename-this-buffer-and-file ()
+  "Renames current buffer and file it is visiting."
+  (interactive)
+  (let ((name (buffer-name))
+        (filename (buffer-file-name))
+        (read-file-name-function 'read-file-name-default))
+    (if (not (and filename (file-exists-p filename)))
+        (error "Buffer '%s' is not visiting a file!" name)
+      (let ((new-name (read-file-name "New name: " filename)))
+        (cond ((get-buffer new-name)
+               (error "A buffer named '%s' already exists!" new-name))
+              (t
+               (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))))))))
+
+(defun my/uniquify-region-lines (beg end)
+  "Remove duplicate adjacent lines in region between BEG and END."
+  (interactive "*r")
+  (save-excursion
+    (goto-char beg)
+    (while (re-search-forward "^\\(.*\n\\)\\1+" end t)
+      (replace-match "\\1"))))
+
 (provide 'my-buffers)
 ;;; my-buffers.el ends here
diff --git a/emacs/elisp/my-clipboard.el b/emacs/elisp/my-clipboard.el
deleted file mode 100644
index f0f3c01..0000000
--- a/emacs/elisp/my-clipboard.el
+++ /dev/null
@@ -1,24 +0,0 @@
-;;; my-clipboard.el --- Functions related to clipboard
-;;; Commentary:
-;;; Code:
-
-;; https://github.com/chongchonghe/emacs-dotfile/blob/f4f9ce5f586f224e2c83b118d471652d65d38e8c/packages/simpleclip.el
-(defun my/clipboard-get-contents ()
-  "Return the contents of the system clipboard as a string."
-  (condition-case nil
-      (cond
-       ((fboundp 'ns-get-pasteboard)
-        (ns-get-pasteboard))
-       ((and (featurep 'mac)
-             (fboundp 'gui-get-selection))
-        (gui-get-selection 'CLIPBOARD 'NSStringPboardType))
-       ((and (featurep 'mac)
-             (fboundp 'x-get-selection))
-        (x-get-selection 'CLIPBOARD 'NSStringPboardType))
-       ((fboundp 'gui-get-selection)
-        (gui-get-selection 'CLIPBOARD (or x-select-request-type 'UTF8_STRING)))
-       (t
-        (error "Clipboard support not available")))))
-
-(provide 'my-clipboard)
-;;; my-clipboard.el ends here
diff --git a/emacs/elisp/my-git-extra.el b/emacs/elisp/my-git-extra.el
new file mode 100644
index 0000000..862286a
--- /dev/null
+++ b/emacs/elisp/my-git-extra.el
@@ -0,0 +1,42 @@
+;;; my-git-extra.el --- Extra functions to work with gitattributes
+;;; Commentary:
+;;; Code:
+
+(require 'magit)
+(require 'git-link)
+
+(defun my/clone-repo (url)
+  "Clone a repository in the workspace using URL."
+  (interactive "sURL:")
+  (let* ((repo-name (magit-clone--url-to-name url))
+         (target-dir (concat  "~/workspace/" repo-name)))
+    (magit-clone-regular url target-dir nil)))
+
+(defun my/get-sg-remote-from-hostname (hostname)
+  "Create a sourcegraph URL from HOSTNAME."
+  (format "sourcegraph.rbx.com/%s" hostname))
+
+(defun my/git-link-work-sourcegraph (hostname dirname filename _branch commit start end)
+  "Create a link to sourcegraph given a HOSTNAME DIRNAME FILENAME _BRANCH COMMIT START and END."
+  ;; Use the default branch of the repository instead of the
+  ;; current one (we might be on a feature branch that is not
+  ;; available on the remote).
+  (let ((sg-base-url (my/get-sg-remote-from-hostname hostname))
+        (main-branch (magit-main-branch)))
+    (git-link-sourcegraph sg-base-url dirname filename main-branch commit start end)))
+
+(defun my/git-link-commit-work-sourcegraph (hostname dirname commit)
+  "Create the link to sourcegraph given a HOSTNAME DIRNAME and COMMIT."
+  (let ((sg-base-url (my/get-sg-remote-from-hostname hostname)))
+    (git-link-commit-sourcegraph sg-base-url dirname commit)))
+
+;; for work related repositories, open them in our instance of sourcegraph
+(add-to-list 'git-link-remote-alist '("github\\.rbx\\.com" my/git-link-work-sourcegraph))
+(add-to-list 'git-link-commit-remote-alist '("github\\.rbx\\.com" my/git-link-commit-work-sourcegraph))
+
+;; for personal code I use gitea, which is similar to codeberg
+(add-to-list 'git-link-remote-alist '("git\\.my\\.net" git-link-codeberg))
+(add-to-list 'git-link-commit-remote-alist '("git\\.my\\.net" git-link-commit-codeberg))
+
+(provide 'my-git-extra)
+;;; my-git-extra.el ends here
diff --git a/emacs/init.el b/emacs/init.el
index 7802db9..cd2d4de 100644
--- a/emacs/init.el
+++ b/emacs/init.el
@@ -54,8 +54,10 @@
 (require 'my-tramp)
 (require 'my-notmuch)
 
-;; ;; (require 'fcuny-defuns)
-;; ;; (require 'fcuny-commands)
+(require 'my-buffers)
+(require 'my-git-extra)
+(require 'my-strings)
+(require 'my-web)
 (require 'my-work)
 
 ;;; init.el ends here
diff --git a/emacs/lisp/fcuny-commands.el b/emacs/lisp/fcuny-commands.el
deleted file mode 100644
index 842fb3e..0000000
--- a/emacs/lisp/fcuny-commands.el
+++ /dev/null
@@ -1,72 +0,0 @@
-;;; fcuny-commands -- my functions
-
-;;; Commentary:
-;;; Code:
-
-(require 'fcuny-vars)
-(require 'magit)
-(require 'magit-branch)
-(require 'git-link)
-
-(defun rename-this-buffer-and-file ()
-  "Renames current buffer and file it is visiting."
-  (interactive)
-  (let ((name (buffer-name))
-        (filename (buffer-file-name))
-        (read-file-name-function 'read-file-name-default))
-    (if (not (and filename (file-exists-p filename)))
-        (error "Buffer '%s' is not visiting a file!" name)
-      (let ((new-name (read-file-name "New name: " filename)))
-        (cond ((get-buffer new-name)
-               (error "A buffer named '%s' already exists!" new-name))
-              (t
-               (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))))))))
-
-(defun uniquify-region-lines (beg end)
-  "Remove duplicate adjacent lines in region between BEG and END."
-  (interactive "*r")
-  (save-excursion
-    (goto-char beg)
-    (while (re-search-forward "^\\(.*\n\\)\\1+" end t)
-      (replace-match "\\1"))))
-
-(defun fcuny/clone-repo (url)
-  "Clone a repository in the workspace using URL."
-  (interactive "sURL:")
-  (let* ((repo-name (magit-clone--url-to-name url))
-         (target-dir (concat fcuny/path-workspace "/" repo-name)))
-    (magit-clone-regular url target-dir nil)))
-
-(defun fcuny/get-sg-remote-from-hostname (hostname)
-  "Create a sourcegraph URL from HOSTNAME."
-  (format "sourcegraph.rbx.com/%s" hostname))
-
-(defun fcuny/git-link-work-sourcegraph (hostname dirname filename _branch commit start end)
-  "Create the link to sourcegraph given a HOSTNAME DIRNAME FILENAME _BRANCH COMMIT START and END."
-  ;; Use the default branch of the repository instead of the
-  ;; current one (we might be on a feature branch that is not
-  ;; available on the remote).
-  (let ((sg-base-url (fcuny/get-sg-remote-from-hostname hostname))
-        (main-branch (magit-main-branch)))
-    (git-link-sourcegraph sg-base-url dirname filename main-branch commit start end)))
-
-(defun fcuny/git-link-commit-work-sourcegraph (hostname dirname commit)
-  "Create the link to sourcegraph given a HOSTNAME DIRNAME and COMMIT."
-  (let ((sg-base-url (fcuny/get-sg-remote-from-hostname hostname)))
-    (git-link-commit-sourcegraph sg-base-url dirname commit)))
-
-;; for work related repositories, open them in our instance of sourcegraph
-(add-to-list 'git-link-remote-alist '("github\\.rbx\\.com" fcuny/git-link-work-sourcegraph))
-(add-to-list 'git-link-commit-remote-alist '("github\\.rbx\\.com" fcuny/git-link-commit-work-sourcegraph))
-
-;; for personal code I use gitea, which is similar to codeberg
-(add-to-list 'git-link-remote-alist '("git\\.fcuny\\.net" git-link-codeberg))
-(add-to-list 'git-link-commit-remote-alist '("git\\.fcuny\\.net" git-link-commit-codeberg))
-
-(provide 'fcuny-commands)
-
-;;; fcuny-commands.el ends here