From: Ian Kelling Date: Wed, 28 May 2025 02:40:24 +0000 (-0400) Subject: general improvements X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=1affba013ef6f9f04e39197f8677b278427aaa3e;p=dot-emacs general improvements --- diff --git a/early-init.el b/early-init.el new file mode 100644 index 0000000..b7d7700 --- /dev/null +++ b/early-init.el @@ -0,0 +1,51 @@ +;; -*- lexical-binding: t; -*- + +;;(defun internal--get-default-lexical-binding (from) +;; (default-toplevel-value 'lexical-binding)) + + +(defun internal--get-default-lexical-binding (from) + (let ((mib (lambda (node) (buttonize node (lambda (_) (info node)) + nil "mouse-2: Jump to Info node")))) + (or (and (bufferp from) (zerop (buffer-size from))) + (and (stringp from) + (eql 0 (file-attribute-size (file-attributes from)))) + (let ((source + (if (not (and (bufferp from) + (string-match-p "\\` \\*load\\*\\(-[0-9]+\\)?\\'" + (buffer-name from)) + load-file-name)) + from + (abbreviate-file-name load-file-name)))) + ;; iank: this is the default function plus this line. because I'm not going + ;; to fix third party packages. + (when (or (bufferp source) (not (string-match-p "/elpa/" source))) + (condition-case nil + (display-warning + `(files missing-lexbind-cookie + ,(if (bufferp source) 'eval-buffer source)) + (format-message "Missing `lexical-binding' cookie in %S. +You can add one with `M-x %s RET'. +See `%s' and `%s' +for more information." + source + (buttonize "elisp-enable-lexical-binding" + (lambda (_) + (pop-to-buffer + (if (bufferp source) source + (find-file-noselect source))) + (call-interactively + #'elisp-enable-lexical-binding)) + nil "mouse-2: Add cookie") + (funcall mib "(elisp)Selecting Lisp Dialect") + (funcall mib "(elisp)Converting to Lexical Binding")) + :warning) + ;; In various corner-case situations, `display-warning' may + ;; fail (e.g. not yet defined, or can't be (auto)loaded), + ;; so use a simple fallback that won't get in the way. + (error + ;; But not if this particular warning is disabled. + (unless (equal warning-inhibit-types + '((files missing-lexbind-cookie))) + (message "Missing `lexical-binding' cookie in %S" source))))))) + (default-toplevel-value 'lexical-binding))) diff --git a/init.el b/init.el index 1701c98..2e0e564 100644 --- a/init.el +++ b/init.el @@ -1,3 +1,4 @@ +;; -*- lexical-binding: t; -*- ;; Copyright (C) 2020 Ian Kelling ;; This program is free software: you can redistribute it and/or modify @@ -24,9 +25,9 @@ -;; stop from minimizing & freezing the gui -;; used to freeze emacs and was really annoying, -;; seems its changed now. no harm in keeping this though. +;; Used to freeze the gui, which it doesn't anymore, but still good to +;; unbind it since we bind it later, in the case that our init.el gets +;; only partially executed. (global-unset-key (kbd "C-z")) ;; emacs holds open files in the eln-cache, preventing umount, so move @@ -68,8 +69,6 @@ ;; ; emacs -f benchmark-init/deactivate -(setq init-dir (file-name-directory load-file-name)) - ;; these need to be done before the hook in order to satisfy the byte compiler or batch mode (add-to-list 'load-path (concat user-emacs-directory "src/readline-complete")) @@ -212,16 +211,8 @@ ;; I'm gonna delete the cache, and check on it later see what exactly is going in there ;; And of course, I moved ~/News to my encrypted drive and symlinked it - - ;;; things that should be at the beginning -;; from its README.md -(eval-when-compile - (require 'use-package)) -(use-package use-package-ensure-system-package - :ensure t) - ;; Ubiquitous Packages. these could go anywhere actually ;; find file at point @@ -262,8 +253,11 @@ ;;(require 'src-loaddefs) +(setenv "EMACS" "") ;; generally unnecessary, but why not -(setq explicit-shell-file-name "bash") +(setq explicit-shell-file-name "bash" + explicit-bash-args nil + comint-process-echoes t) ;; readline-complete says to add this line. ;; however, it up my procfs directory tracking hook @@ -274,9 +268,6 @@ ;; and done stty echo in my bashrc ;;(setq explicit-bash-args '("-c" "export EMACS=; stty echo; bash")) -(setenv "EMACS" "") -(setq explicit-bash-args nil) -(setq comint-process-echoes t) ;; todo: consider if this is needed in company mode. @@ -362,6 +353,9 @@ ;;(define-key keymap "\C-\M-s" 'company-filter-candidates) (define-key company-active-map "\C-\M-s" nil) + ;; taken from readline-complete.el . to fully switch over to company mode, uncomment these + ;;(push 'company-readline company-backends) + ;;(add-hook 'rlc-no-readline-hook (lambda () (company-mode -1))) ) (add-hook 'after-init-hook 'my-company-config) @@ -649,7 +643,7 @@ A non-nil CURRENT-ONLY argument means save only current buffer." (use-package recentf ;; defer & commands from jwiegley - :defer 10 + :defer 5 :if (string= (daemonp) "server") :commands (recentf-mode recentf-add-file @@ -686,17 +680,123 @@ A non-nil CURRENT-ONLY argument means save only current buffer." savehist-file (concat user-emacs-directory ".savehist")) (savehist-mode 1)) +;;; vertico +(setq read-file-name-completion-ignore-case t + read-buffer-completion-ignore-case t + completion-ignore-case t) + +;; Enable Vertico. +(use-package vertico + :custom + ;; (vertico-scroll-margin 0) ;; Different scroll margin + (vertico-count 20) ;; Show more candidates + ;;(vertico-resize t) ;; Grow and shrink the Vertico minibuffer + (vertico-cycle t) ;; Enable cycling for `vertico-next/previous' + (keymap-set vertico-map "TAB" #'minibuffer-complete) + :init + (vertico-mode)) + +;; Emacs minibuffer configurations. +(use-package emacs + :custom + ;; Support opening new minibuffers from inside existing minibuffers. + (enable-recursive-minibuffers t) + ;; Hide commands in M-x which do not work in the current mode. Vertico + ;; commands are hidden in normal buffers. This setting is useful beyond + ;; Vertico. + (read-extended-command-predicate #'command-completion-default-include-p) + ;; Do not allow the cursor in the minibuffer prompt + (minibuffer-prompt-properties + '(read-only t cursor-intangible t face minibuffer-prompt))) + +(use-package orderless + :custom + ;; Configure a custom style dispatcher (see the Consult wiki) + ;; (orderless-style-dispatchers '(+orderless-consult-dispatch orderless-affix-dispatch)) + ;; (orderless-component-separator #'orderless-escapable-split-on-space) + (completion-styles '(orderless basic)) + (completion-category-defaults nil) + (completion-category-overrides '((file (styles partial-completion))))) + ;;; image dired -;; dont see how to make this change existing thumbs -;; image-dired-thumb-size +(setq image-dired-debug t + image-dired-marking-shows-next nil + ;; just testing it out in case + image-dired-track-movement nil + image-dired-thumb-margin 1 + ;; odd useless borders + image-dired-thumb-relief 0 + image-auto-resize 'fit-window + image-dired-thumb-size 400 + ;; image-dired-cmd-create-temp-image-options ("convert" "-size" "%wx%h" "%f[0]" "-resize" "%wx%h>" "-strip" "jpeg:%t" "-filter" "Lanczos" "-colorspace" "RGB" "-define" "jpeg:dct-method=float" "-quality" "95") + ;;image-dired-cmd-create-thumbnail-options ("convert" "-size" "%wx%h" "%f[0]" "-resize" "%wx%h>" "-strip" "jpeg:%t" "-filter" "Lanczos" "-colorspace" "RGB" "-define" "jpeg:dct-method=float" "-quality" "95") + image-dired-cmd-create-thumbnail-options '("convert" "%f" "-strip" "-resize" "%wx%h" "-filter" "Lanczos" "-define" "jpeg:dct-method=float" "-quality" "95" "%t") + image-dired-cmd-create-thumbnail-options '("true") + ) + + +(defun imgdired-rating () + "highlight" + (interactive) + (with-current-buffer image-dired-thumbnail-buffer + (save-mark-and-excursion + (goto-char (point-min)) + (let ((inhibit-read-only t)) + (while (not (eobp)) + (when-let* ((file-path (image-dired-original-file-name)) + (file (file-name-nondirectory file-path))) + (image-dired-rating-highlight-at-point file)) + (forward-char 2)))))) + +;; find new faces with (list-faces-display) +(defun image-dired-rating-highlight-at-point (file) + (with-silent-modifications + (let* ((rating (gethash file khash))) + (cond ((and rating (>= rating 4)) + (add-face-text-property (point) (1+ (point)) + 'shr-mark)) + ((and rating (= rating 3)) + (add-face-text-property (point) (1+ (point)) + 'reb-match-1)) + ((and rating (= rating 1)) + ;; brown + (add-face-text-property (point) (1+ (point)) + 'reb-match-3)) + (t (remove-text-properties (point) (1+ (point)) + '(face reb-match-1))))))) + +;; successfull font markup test: +;; (with-silent-modifications (add-face-text-property (point) (+ 10 (point)) 'image-dired-thumb-mark)) +;; ;; [45] bright yellow: shr-mark +;; ;; [3] medium blue: reb-match-1 +;; ;; [12] light brown +;; + +;; scratch pad for looking over the thumb width calculations: +;; char-width: (frame-char-width) = 9 +;; width: (window-body-width (image-dired-thumbnail-window) t) = 2777 + + +;; The same-window helps prevent image-dired window from jumping all around, but it doesn't completely stop it. + +;; (setq display-buffer-alist '((".*" display-buffer-reuse-window))) +;; (setq display-buffer-alist '((".*" display-buffer-in-previous-window))) +;; (setq display-buffer-alist '((".*" display-buffer-same-window))) +;; (setq display-buffer-alist nil) +;; (setq image-dired-track-movement nil) +;; (setq image-dired-track-movement t) +;; +;; I eventually solved it based on a patch in debbugs waiting for review. + + ;;; dired ;; dired - reuse current buffer by pressing 'a' -(put 'dired-find-alternate-file 'disabled nil) +;;(put 'dired-find-alternate-file 'disabled nil) ;; copied from dired-x info manual @@ -1020,14 +1120,6 @@ A non-nil CURRENT-ONLY argument means save only current buffer." (temp-buffer-resize-mode 1) -(defun my-info-init() - (require 'info+) - ;; based on suggestions in info+.el, I also installed misc-fns, strings, and thingatpt+ - ;; remove some bad keybinds from info+ - (define-key Info-mode-map [mouse-4] nil) - (define-key Info-mode-map [mouse-5] nil)) - -(add-hook 'info-mode-hook 'my-info-init) ;;; misc general settings @@ -1104,9 +1196,7 @@ A non-nil CURRENT-ONLY argument means save only current buffer." -(ivy-mode 1) (add-hook 'text-mode-hook (lambda () (auto-fill-mode t))) -(setq counsel-find-file-at-point t) (eval-after-load "ido" ;; easier to read with just spaces as separator @@ -1503,6 +1593,13 @@ Go to the next directory based on where the cursor is." ;;; prog-mode-defaults +(defface highlight-symbol-face + '((((class color) (background dark)) + (:background "gray30")) + (((class color) (background light)) + (:background "gray90"))) + "highlight-symbol-face copied from `highlight-symbol-mode' for use in maintained replacement mode: highlight-thing-mode.") + (defun prog-mode-defaults () "Default coding hook, useful with any programming language." @@ -1513,7 +1610,11 @@ Go to the next directory based on where the cursor is." ;; todo, this is causing error message on loading file, prolly not working ;;(flycheck-mode +1) - (highlight-symbol-mode) + (idle-highlight-mode) + (setq idle-highlight-idle-time 0.1) + + + (make-local-variable 'column-number-mode) ;; this says do autofilling using newcomment.el. The "only" is a misnomer. (set (make-local-variable 'comment-auto-fill-only-comments) t) @@ -1638,12 +1739,7 @@ or else the number of characters matched by `outline-regexp'." ispell-program-name "hunspell" ispell-silently-savep t) ; don't prompt to save personal dictionary -(use-package rw-hunspell - :defer t) -;; rw-hunspell sets up hunspell dictionary automagically. - (use-package flyspell - :ensure-system-package hunspell :hook ((prog-mode . flyspell-prog-mode) (text-mode . turn-on-flyspell))) @@ -2058,6 +2154,7 @@ or else the number of characters matched by `outline-regexp'." (setq dir parent-dir parent-dir (file-name-directory (directory-file-name parent-dir)))) nearest-compilation-file)) + (defun run () (interactive) "call run-fun if it is set, else run make if there is a makefile, @@ -2153,14 +2250,14 @@ modes like org-mode which have their own yank function." (switch-to-buffer original-buffer) (setq buffer (get-buffer buffer-name))) (error "No existing buffer found and no init function argument. "))) - (buffer-window-show buffer) + (iank-buffer-window-show buffer) (with-current-buffer buffer (let ((proc (get-buffer-process buffer))) (goto-char (process-mark proc)) (insert string) (comint-send-input nil t))))) -(defun buffer-window-show (&optional buffer action) +(defun iank-buffer-window-show (&optional buffer action) "Like temp-buffer-window-show, but removed stuff relevant to it being temp or help." (let (window frame) @@ -2197,9 +2294,13 @@ modes like org-mode which have their own yank function." ;; but those things are often nil. ;; aha moments in reading it: ACTION = (FUNCTION-or-FUNCTIONLIST ALIST) ;; FRAME adds an association to ACTION's alist, but it's not used if ACTION arg is nil. +;; (setq display-buffer-fallback-action `(,(car display-buffer-fallback-action) . '(reusable-frames . visible))) + ;; stop splitting windows verticallly when I open a buffer or shell (setq split-height-threshold nil) +;; 2025: trying this out just to experiment. +(setq split-width-threshold nil) ;;;;; s-left arrow - --- ;; cant be used in terminal @@ -2357,9 +2458,11 @@ modes like org-mode which have their own yank function." (global-set-key (kbd "C-M-q") 'quoted-insert) -;;;;; C-w counsel-find-file +;;;;; C-w find-file -(global-set-key (kbd "C-w") 'counsel-find-file) +(global-set-key (kbd "C-w") 'ffap) +;; old, just fyi +;;(global-set-key (kbd "C-w") 'counsel-find-file) ;;;;; M-w shell @@ -2521,9 +2624,10 @@ modes like org-mode which have their own yank function." (global-set-key (kbd "C-M-g") 'mu4e) -;;;;; C-z - undo-only +;;;;; C-z - undo ;;(global-set-key (kbd "C-z") 'undo-tree-undo) (global-set-key (kbd "C-z") 'undo-fu-only-undo) +;; originally: suspend-emacs (might want to call manually in tty sometimes) ;;;;; C-M-z - suspend-frame (global-set-key (kbd "C-M-z") 'suspend-frame) ;; this is never good in a gui @@ -2534,17 +2638,9 @@ modes like org-mode which have their own yank function." (global-set-key (kbd "C-s") 'kill-region) -;;;;; M-x - counsel-m-x +;;;;; M-x - m-x -;; todo; check out smex-show-unbound-commands shows frequently used commands that have no key bindings. -;; this must be before smex-initialize -(setq - smex-save-file (concat user-emacs-directory ".smex-items")) - -;; this uses smex -(global-set-key (kbd "M-x") 'counsel-M-x) - ;;;;; C-M-x - cut-to-register ;; same args as copy-to-register @@ -2562,9 +2658,19 @@ modes like org-mode which have their own yank function." (global-set-key (kbd "C-d") 'kill-ring-save) -;; by default is does image-dired-delete-character, pretty useless. +;; by default is does image-dired-delete-character (stops displaying its thumbnail), pretty useless. (add-hook 'image-dired-thumbnail-mode-hook (lambda () + (define-key image-dired-thumbnail-mode-map (kbd ",") 'image-dired-copy-filename-r1) + (define-key image-dired-thumbnail-mode-map (kbd ".") 'image-dired-copy-filename-r2) + (define-key image-dired-thumbnail-mode-map (kbd "/") 'image-dired-copy-filename-r3) + (define-key image-dired-thumbnail-mode-map (kbd "k") 'image-dired-copy-filename-r4) + (define-key image-dired-thumbnail-mode-map (kbd "l") 'image-dired-copy-filename-r5) + (define-key image-dired-thumbnail-mode-map (kbd "u") 'image-dired-copy-filename-ban) + (define-key image-dired-thumbnail-mode-map (kbd "y") 'image-dired-copy-filename-draw) + (define-key image-dired-thumbnail-mode-map (kbd "h") 'image-dired-copy-filename-tame) + (define-key image-dired-thumbnail-mode-map (kbd "o") 'image-dired-copy-filename-tbdremix) + (define-key image-dired-thumbnail-mode-map (kbd "n") 'image-dired-copy-filename-remix) (define-key image-dired-thumbnail-mode-map (kbd "C-d") nil))) @@ -2594,9 +2700,6 @@ modes like org-mode which have their own yank function." (global-set-key (kbd "C-v") 'yank-better) -(add-hook 'ivy-mode-hook - (lambda () - (define-key ivy-minibuffer-map (kbd "C-v") nil))) @@ -2785,9 +2888,10 @@ modes like org-mode which have their own yank function." (global-set-key (kbd "C-o") 'occur) -;;;;; C-M-o - counsel-imenu +;;;;; C-M-o - imenu -(global-set-key (kbd "C-M-o") 'counsel-imenu) +(global-set-key (kbd "C-M-o") 'imenu) +;; note: previously: counsel-imenu ;;;;; C-p - move-mouse-to-point @@ -2840,9 +2944,10 @@ modes like org-mode which have their own yank function." (global-set-key (kbd "C-M-k") 'man) -;;;;; C-l - ivy-switch-buffer +;;;;; C-l - switch-buffer -(global-set-key (kbd "C-l") 'ivy-switch-buffer) +(global-set-key (kbd "C-l") 'switch-to-buffer) +;; was ivy-switch-buffer ;;;;; C-M-l - move cursor top bottom mid, comint clear screen @@ -2886,10 +2991,11 @@ modes like org-mode which have their own yank function." (add-hook 'flyspell-mode-hook (lambda () (define-key flyspell-mode-map (kbd "C-.") nil))) (define-key dot-mode-map (kbd "C-.") nil) -(define-key terminal-key-map (kbd "4c") 'counsel-recentf) -(global-set-key (kbd "C-.") 'counsel-recentf) +(define-key terminal-key-map (kbd "4c") 'recentf) +(global-set-key (kbd "C-.") 'recentf) (add-hook 'php-mode-hook (lambda () (define-key php-mode-map (kbd "C-.") nil))) +;; note: previously counsel-recentf ;;;;; C-M-. - - @@ -2985,10 +3091,11 @@ modes like org-mode which have their own yank function." (global-set-key (kbd "") 'winner-redo) -;;;;; C-S-down-arrow - m-x for major mode +;;;;; C-S-down-arrow - unused (text-scale-increase) -;; todo, update this for ivy -(global-set-key (kbd "") 'smex-major-mode-commands) +;; Disabled cuz i never ended up sing it +;; todo, update this for ivy or whatever else +;; (global-set-key (kbd "") 'smex-major-mode-commands) ;;;;; C-lbracket - ---- ;;;;; C-M-lbracket - scroll-right diff --git a/misc-disabled.el b/misc-disabled.el index 1830526..55cfff6 100644 --- a/misc-disabled.el +++ b/misc-disabled.el @@ -1,3 +1,60 @@ +;;; packages i never fully explored: +;; ansible-doc swiper ivy-hydra ivy hydra counsel +;; outorg mouse+ outshine mastodon + + +;;; misc general settings + +;; disabled cuz trying out vertico +(ivy-mode 1) +;; todo: this belongs in use-package +(add-hook 'ivy-mode-hook + (lambda () + (define-key ivy-minibuffer-map (kbd "C-v") nil))) + +(setq counsel-find-file-at-point t) + + +;;;; removed due to lexical-binding warning. This adds readability highlights to info mode, trying without. +(defun my-info-init() + (require 'info+) + ;; based on suggestions in info+.el, I also installed misc-fns, strings, and thingatpt+ + ;; remove some bad keybinds from info+ + (define-key Info-mode-map [mouse-4] nil) + (define-key Info-mode-map [mouse-5] nil)) + +(add-hook 'info-mode-hook 'my-info-init) + + + +;;;; I briefly put this in prog-mode-defaults when looking for a maintained replacement of highlight-symbol, +;;;; but I found a different package that was more maintained. +;; (highlight-thing-mode) +;; (setq highlight-thing-limit-to-region-in-large-buffers-p t +;; highlight-thing-narrow-region-lines 40 +;; highlight-thing-large-buffer-limit 5000) +;; ;; highlight-symbol-face copied from `highlight-symbol-mode' for use +;; ;; in maintained replacement mode: highlight-thing-mode. +;; (face-spec-set 'highlight-thing +;; '((((class color) (background dark)) +;; (:background "gray30")) +;; (((class color) (background light)) +;; (:background "gray90"))) +;; 'face-defface-spec) + + + + + + +;; mastodon +(setq mastodon-instance-url "https://hostux.social" + mastodon-active-user "iank") + + + + + ;; auto-completion in minibuffer ;; disabled while I look for another alternative ;;(icomplete-mode) @@ -640,3 +697,15 @@ (message "Buffer and window marked for swapping.")))) (global-set-key (kbd "C-M-d") 'swap-buffers-in-windows) + + +;;;;; M-x - m-x + + +;; todo; check out smex-show-unbound-commands shows frequently used commands that have no key bindings. +;; this must be before smex-initialize +(setq + smex-save-file (concat user-emacs-directory ".smex-items")) + +;; this uses smex +(global-set-key (kbd "M-x") 'counsel-M-x)