From ea1e815c3dc1781aa5cb6d401e233c73fa8a108b Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 26 Jun 2023 15:17:20 +1000 Subject: Adapted more configs from other emacs configs Including wasamasa and jwiegley --- emacs/.emacs.d/lisp/my/my-buffer.el | 2 -- emacs/.emacs.d/lisp/my/my-corfu.el | 2 -- emacs/.emacs.d/lisp/my/my-editing.el | 22 ++++++++++++++--- emacs/.emacs.d/lisp/my/my-hnreader.el | 2 -- emacs/.emacs.d/lisp/my/my-org.el | 19 +++++++++++++-- emacs/.emacs.d/lisp/my/my-package.el | 7 ++++-- emacs/.emacs.d/lisp/my/my-prog.el | 39 ++++++++++++++++++++++++++---- emacs/.emacs.d/lisp/my/my-project.el | 45 +++++++++++++++++++++++++++++++++++ emacs/.emacs.d/lisp/my/my-system.el | 36 ++++++++++++++++++++++++++++ emacs/.emacs.d/lisp/my/my-utils.el | 5 ++++ 10 files changed, 161 insertions(+), 18 deletions(-) create mode 100644 emacs/.emacs.d/lisp/my/my-system.el (limited to 'emacs/.emacs.d/lisp/my') diff --git a/emacs/.emacs.d/lisp/my/my-buffer.el b/emacs/.emacs.d/lisp/my/my-buffer.el index 9c7da4a..abe007f 100644 --- a/emacs/.emacs.d/lisp/my/my-buffer.el +++ b/emacs/.emacs.d/lisp/my/my-buffer.el @@ -3,8 +3,6 @@ ;; Copyright (C) 2023 Free Software Foundation. ;; Author: Yuchen Pei -;; Protesilaos Stavrou -;; Maintainer: Yuchen Pei ;; Package-Requires: ((emacs "28.2")) ;; This file is part of dotfiles. diff --git a/emacs/.emacs.d/lisp/my/my-corfu.el b/emacs/.emacs.d/lisp/my/my-corfu.el index 191f513..2d1ba27 100644 --- a/emacs/.emacs.d/lisp/my/my-corfu.el +++ b/emacs/.emacs.d/lisp/my/my-corfu.el @@ -3,8 +3,6 @@ ;; Copyright (C) 2023 Free Software Foundation. ;; Author: Yuchen Pei -;; Protesilaos Stavrou -;; Maintainer: Yuchen Pei ;; Package-Requires: ((emacs "28.2")) ;; This file is part of dotfiles. diff --git a/emacs/.emacs.d/lisp/my/my-editing.el b/emacs/.emacs.d/lisp/my/my-editing.el index 47e33a3..940a338 100644 --- a/emacs/.emacs.d/lisp/my/my-editing.el +++ b/emacs/.emacs.d/lisp/my/my-editing.el @@ -3,9 +3,6 @@ ;; Copyright (C) 2023 Free Software Foundation. ;; Author: Yuchen Pei -;; Protesilaos Stavrou -;; Stefan Monnier -;; Maintainer: Yuchen Pei ;; Package-Requires: ((emacs "28.2")) ;; This file is part of dotfiles. @@ -336,6 +333,13 @@ Basically move the line up (goto-line line) (forward-char col))) +(defun my-kill-line (&optional arg) + "Calls `my-kill-forward' or `kill-line' in case of prefix arg." + (interactive "P") + (if prefix-arg + (kill-line) + (my-kill-forward))) + (defun my-kill-forward () "Kill towards end of line, but not out of sexp." (interactive) @@ -354,6 +358,13 @@ Basically move the line up (setq end (point))) (kill-region (point) end)))) +(defun my-kill-line-backward (&optional arg) + "Calls `my-kill-backward' or `kill-line' with 0 in case of prefix arg." + (interactive "P") + (if prefix-arg + (kill-line 0) + (my-kill-backward))) + (defun my-kill-backward () "Kill towards beginning of line, but not out of sexp." (interactive) @@ -385,5 +396,10 @@ With an prefix-arg, copy the file name relative to project root." (kill-new to-kill) (message "Copied %s" to-kill))) +(defun my-non-special-modes-setup () + (setq indicate-empty-lines t) + (setq show-trailing-whitespace t) + ) + (provide 'my-editing) ;;; my-editing.el ends here diff --git a/emacs/.emacs.d/lisp/my/my-hnreader.el b/emacs/.emacs.d/lisp/my/my-hnreader.el index 4176f8b..6106d29 100644 --- a/emacs/.emacs.d/lisp/my/my-hnreader.el +++ b/emacs/.emacs.d/lisp/my/my-hnreader.el @@ -3,8 +3,6 @@ ;; Copyright (C) 2023 Free Software Foundation. ;; Author: Yuchen Pei -;; Thanh Vuong -;; Maintainer: Yuchen Pei ;; Package-Requires: ((emacs "28.2")) ;; This file is part of dotfiles. diff --git a/emacs/.emacs.d/lisp/my/my-org.el b/emacs/.emacs.d/lisp/my/my-org.el index 4c69484..4b8ad44 100644 --- a/emacs/.emacs.d/lisp/my/my-org.el +++ b/emacs/.emacs.d/lisp/my/my-org.el @@ -95,8 +95,23 @@ With a prefix, insert inactive dates. (save-restriction (org-narrow-to-subtree) (goto-char (point-min)) - (when (re-search-forward "^\\s-*:PROPERTIES:" nil t) - (org-hide-drawer-toggle))))) + (while (re-search-forward "^\\ *:[A-Z]+:\\ *$" nil t) + (org-hide-drawer-toggle) + (re-search-forward "^\\ *:END:\\ *$" nil t))))) + +(defun my-org-beginning-of-line-or-indent () + "Move to org beginning of line, or indentation" + (interactive) + (if (bolp) + (back-to-indentation) + (org-beginning-of-line))) + +(defun my-org-kill-line (&optional arg) + "Call `my-kill-forward' or `org-kill-line' with a prefix arg." + (interactive "P") + (if arg + (org-kill-line) + (my-kill-forward))) (defun my-org-open-default-notes-file () (interactive) diff --git a/emacs/.emacs.d/lisp/my/my-package.el b/emacs/.emacs.d/lisp/my/my-package.el index 1f35a5e..da4ff6f 100644 --- a/emacs/.emacs.d/lisp/my/my-package.el +++ b/emacs/.emacs.d/lisp/my/my-package.el @@ -3,8 +3,6 @@ ;; Copyright (C) 2023 Free Software Foundation. ;; Author: Yuchen Pei -;; Protesilaos Stavrou -;; Maintainer: Yuchen Pei ;; Package-Requires: ((emacs "28.2")) ;; This file is part of dotfiles. @@ -259,5 +257,10 @@ same name, cancel that one first." (t (append (my-collect-my-setqd-vars (car xs)) (my-collect-my-setqd-vars (cdr xs)))))) +(defsubst my-add-hooks (function hooks) + "Add function to hooks" + (dolist (hook hooks) + (add-hook hook function))) + (provide 'my-package) ;;; my-package.el ends here diff --git a/emacs/.emacs.d/lisp/my/my-prog.el b/emacs/.emacs.d/lisp/my/my-prog.el index 4794ff2..ca54ad9 100644 --- a/emacs/.emacs.d/lisp/my/my-prog.el +++ b/emacs/.emacs.d/lisp/my/my-prog.el @@ -48,12 +48,30 @@ (comint-previous-prompt 1) (recenter 0 t)) -;; FIXME: not working properly -(defun my-restart-shell () +(defun my-comint-restart () (interactive) - (ignore-error (comint-send-eof)) - (shell (current-buffer)) - (message "Shell restarted!")) + (ignore-errors (comint-send-eof)) + (sleep-for .1) + (my-comint-revive)) + +(defvar my-comint-revive-commands + '((shell-mode . my-shell-revive) + (inferior-emacs-lisp-mode . ielm)) + "Alist of commands for each comint derived mode to revive a \"no + process\" buffer ") + +(defun my-shell-revive () + (interactive) + (shell (current-buffer))) + +(defun my-comint-revive () + "Revive a comint process after death" + (interactive) + (if-let ((revive-command (alist-get major-mode + my-comint-revive-commands))) + (funcall revive-command) + (error "I don't know how to restart in %S" major-mode)) + ) (defun my-shell-disable-company-if-remote () (when (and (fboundp 'company-mode) @@ -444,5 +462,16 @@ left and the source buffer on the right. (eval-region (region-beginning) (region-end) t) (eval-defun arg))) +(defun my-insert-current-prefix () + "Insert file basename followed by a dash" + (interactive) + (insert (file-name-base (buffer-file-name)) "-")) + +(defun my-prog-modes-setup () + (setq-local comment-auto-fill-only-comments t) + (auto-fill-mode) + (display-line-numbers-mode) + (setq tab-width 2)) + (provide 'my-prog) ;;; my-prog.el ends here diff --git a/emacs/.emacs.d/lisp/my/my-project.el b/emacs/.emacs.d/lisp/my/my-project.el index 21a05f1..6835487 100644 --- a/emacs/.emacs.d/lisp/my/my-project.el +++ b/emacs/.emacs.d/lisp/my/my-project.el @@ -61,6 +61,51 @@ "Remember all projects under `my-projects-root-dirs'." (pcase-dolist (`(_ . ,dir) my-projects-root-dirs) (project-remember-projects-under dir))) + +;; Override project-remember-projects-under The original function is +;; buggy: it does not look for projects in surdirs unless recursive. +(defun my-project-remember-projects-under (dir &optional recursive) + "Index all projects below a directory DIR. +If RECURSIVE is non-nil, recurse into all subdirectories to find +more projects. After finishing, a message is printed summarizing +the progress. The function returns the number of detected +projects." + (interactive "DDirectory: \nP") + (project--ensure-read-project-list) + (let ((queue (directory-files + dir + t + directory-files-no-dot-files-regexp)) + (count 0) + (known (make-hash-table + :size (* 2 (length project--list)) + :test #'equal ))) + (dolist (project (mapcar #'car project--list)) + (puthash project t known)) + (while queue + (when-let ((subdir (pop queue)) + ((file-directory-p subdir))) + (when-let ((project (project--find-in-directory subdir)) + (project-root (project-root project)) + ((not (gethash project-root known)))) + (project-remember-project project t) + (puthash project-root t known) + (message "Found %s..." project-root) + (setq count (1+ count))) + (when (and recursive (file-directory-p subdir)) + (setq queue + (nconc + (directory-files + subdir t directory-files-no-dot-files-regexp t) + queue))))) + (unless (eq recursive 'in-progress) + (if (zerop count) + (message "No projects were found") + (project--write-project-list) + (message "%d project%s were found" + count (if (= count 1) "" "s")))) + count)) + ;; FIXME: do we really need this or does the project package already ;; do so? (defun my-project-read-project () diff --git a/emacs/.emacs.d/lisp/my/my-system.el b/emacs/.emacs.d/lisp/my/my-system.el new file mode 100644 index 0000000..f22c982 --- /dev/null +++ b/emacs/.emacs.d/lisp/my/my-system.el @@ -0,0 +1,36 @@ +;;; my-system.el -- Extensions to emacs builtins working with the underlying system -*- lexical-binding: t -*- + +;; Copyright (C) 2023 Free Software Foundation. + +;; Author: Yuchen Pei +;; Package-Requires: ((emacs "28.2")) + +;; This file is part of dotted. + +;; dotted is free software: you can redistribute it and/or modify it under +;; the terms of the GNU Affero General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; dotted is distributed in the hope that it will be useful, but WITHOUT +;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General +;; Public License for more details. + +;; You should have received a copy of the GNU Affero General Public +;; License along with dotted. If not, see . + +;;; Commentary: + +;; Extensions to emacs builtins working with the underlying system. + +;;; Code: + +(defun my-file-handlers-without-tramp () + (seq-filter + (lambda (pair) + (not (string-match-p "^tramp" (symbol-name (cdr pair))))) + file-name-handler-alist)) + +(provide 'my-system) +;;; my-system.el ends here diff --git a/emacs/.emacs.d/lisp/my/my-utils.el b/emacs/.emacs.d/lisp/my/my-utils.el index 7f36fae..fcaba11 100644 --- a/emacs/.emacs.d/lisp/my/my-utils.el +++ b/emacs/.emacs.d/lisp/my/my-utils.el @@ -406,4 +406,9 @@ With optional N, search in the Nth line from point." (looking-at (alist-get type my--line-regexp-alist)))))) +(defun my-quit-emacs (arg) + (interactive "P") + (save-some-buffers t t) + (kill-emacs)) + (provide 'my-utils) -- cgit v1.2.3