From e24f418e3499afd1e9e529b8656a35376e69f52a Mon Sep 17 00:00:00 2001 From: Marc Coquand Date: Tue, 22 Oct 2024 11:07:59 +0300 Subject: initial commit --- home/dots/.emacs.d/elisp/almost-mono-themes.el | 205 ++++++++++++++++++++++++ home/dots/.emacs.d/elisp/exwm-mff.el | 191 ++++++++++++++++++++++ home/dots/.emacs.d/elisp/org-link-minor-mode.el | 137 ++++++++++++++++ 3 files changed, 533 insertions(+) create mode 100644 home/dots/.emacs.d/elisp/almost-mono-themes.el create mode 100644 home/dots/.emacs.d/elisp/exwm-mff.el create mode 100644 home/dots/.emacs.d/elisp/org-link-minor-mode.el (limited to 'home/dots/.emacs.d/elisp') diff --git a/home/dots/.emacs.d/elisp/almost-mono-themes.el b/home/dots/.emacs.d/elisp/almost-mono-themes.el new file mode 100644 index 0000000..4b7769e --- /dev/null +++ b/home/dots/.emacs.d/elisp/almost-mono-themes.el @@ -0,0 +1,205 @@ +;;; almost-mono-themes.el --- Almost monochromatic color themes -*- lexical-binding: t; -*- + +;; Copyright (C) 2019 - 2022 John Olsson + +;; Author: John Olsson +;; Maintainer: John Olsson +;; URL: https://github.com/cryon/almost-mono-themes +;; Created: 9th May 2019 +;; Version: 1.0.0 +;; Keywords: faces +;; Package-Requires: ((emacs "24")) + +;; This file is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published +;; by the Free Software Foundation, either version 3 of the License, +;; or (at your option) any later version. + +;; This file 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 +;; General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this file. If not, see . + +;;; Commentary: + +;; A suite of almost monochrome Emacs themes + +;;; Code: + +(defconst almost-mono-themes-colors + '((white . ((background . "#ffffff") + (foreground . "#000000") + (weak . "#888888") + (weaker . "#dddddd") + (weakest . "#efefef") + (highlight . "#fda50f") + (warning . "#ff0000") + (success . "#00ff00") + (string . "#3c5e2b"))) + + (black . ((background . "#000000") + (foreground . "#ffffff") + (weak . "#aaaaaa") + (weaker . "#666666") + (weakest . "#222222") + (highlight . "#fda50f") + (warning . "#ff0000") + (success . "#00ff00") + (string . "#a7bca4"))) + + (gray . ((background . "#2b2b2b") + (foreground . "#ffffff") + (weak . "#aaaaaa") + (weaker . "#666666") + (weakest . "#222222") + (highlight . "#fda50f") + (warning . "#ff0000") + (success . "#00ff00") + (string . "#a7bca4"))) + + (cream . ((background . "#f0e5da") + (foreground . "#000000") + (weak . "#7d7165") + (weaker . "#c4baaf") + (weakest . "#dbd0c5") + (highlight . "#fda50f") + (warning . "#ff0000") + (success . "#00ff00") + (string . "#3c5e2b"))))) + +(defmacro almost-mono-themes--variant-with-colors (variant &rest body) + "Execute BODY in a scope where the different colors for given VARIANT is bound." + `(let* ((colors (or (cdr (assoc ,variant almost-mono-themes-colors)) + (error "No such theme variant"))) + (background (cdr (assoc 'background colors))) + (foreground (cdr (assoc 'foreground colors))) + (weak (cdr (assoc 'weak colors))) + (weaker (cdr (assoc 'weaker colors))) + (weakest (cdr (assoc 'weakest colors))) + (highlight (cdr (assoc 'highlight colors))) + (warning (cdr (assoc 'warning colors))) + (success (cdr (assoc 'success colors))) + (string (cdr (assoc 'string colors)))) + ,@body)) + +(defmacro almost-mono-themes--faces-spec () + "Provide the faces specification." + (quote + (mapcar + (lambda (entry) (list (car entry) `((t ,@(cdr entry))))) + `( + + ;; default + (default (:background ,background :foreground ,foreground)) + (fringe (:background ,background)) + (region (:background ,highlight :foreground ,foreground)) + (show-paren-match (:background ,background :foreground ,success :bold t)) + (show-paren-mismatch (:background ,background :foreground ,warning :bold t)) + (minibuffer-prompt (:weight bold :foreground ,foreground)) + (isearch (:background ,weak :foreground ,foreground :bold t)) + (lazy-highlight (:background ,weaker :foreground ,foreground)) + (link (:underline t)) + + ;; mode line + (mode-line (:box (:line-width -1 :color ,weaker) + :background ,weakest :foreground ,foreground)) + + (mode-line-inactive (:box (:line-width -1 :color ,weaker) + :background ,background :foreground ,weaker)) + + ;; font lock + (font-lock-keyword-face (:bold t)) + (font-lock-function-name-face (:bold t)) + (font-lock-variable-name-face (:foreground ,foreground)) + (font-lock-warning-face (:foreground ,foreground :underline (:color ,warning :style wave))) + (font-lock-builtin-face (:bold t)) + (font-lock-variable-name-face (:foreground ,foreground :italic t)) + (font-lock-constant-face (:bold t :italic t)) + (font-lock-type-face (:italic t)) + (font-lock-preprocessor-face (:italic t)) + (font-lock-comment-face (:foreground ,weak :italic t)) + (font-lock-string-face (:foreground ,string)) + (font-lock-doc-face (:inherit font-lock-comment-face)) + (line-number (:foreground ,weaker)) + (linum (:inherit line-number)) + (vertical-border (:foreground ,weaker)) + + ;; eshell + (eshell-prompt (:foreground ,foreground :bold t)) + (eshell-ls-directory (:foreground ,foreground :bold t)) + (eshell-ls-archive (:inherit eshell-ls-unreadable)) + (eshell-ls-backup (:inherit eshell-ls-unreadable)) + (eshell-ls-clutter (:inherit eshell-ls-unreadable)) + (eshell-ls-executable (:inherit eshell-ls-unreadable)) + (eshell-ls-missing (:inherit eshell-ls-unreadable)) + (eshell-ls-product (:inherit eshell-ls-unreadable)) + (eshell-ls-readonly (:inherit eshell-ls-unreadable)) + (eshell-ls-special (:inherit eshell-ls-unreadable)) + (eshell-ls-symlink (:inherit eshell-ls-unreadable)) + + ;; company mode + (company-tooltip (:background ,weakest :foreground ,foreground)) + (company-tooltip-selection (:background ,weaker :foreground ,foreground)) + ;;(company-tooltip-search (:background "#ff0000" :foreground "#00ff00")) + (company-tooltip-common (:bold t)) + (company-tooltip-common-selection (:bold t)) + (company-scrollbar-bg (:background ,weaker)) + (company-scrollbar-fg (:background ,weak)) + (company-tooltip-annotation-selection (:background ,weaker :foreground ,foreground :italic t)) + (company-tooltip-annotation (:background ,weakest :foreground ,weak :italic t)) + + ;; git gutter + (git-gutter:modified (:background ,highlight :foreground ,highlight)) + (git-gutter:added (:background ,success :foreground ,success)) + (git-gutter:deleted (:background ,warning :foreground ,warning)) + + ;; diff hl + (diff-hl-change (:background ,highlight :foreground ,highlight)) + (diff-hl-insert (:background ,success :foreground ,success)) + (diff-hl-delete (:background ,warning :foreground ,warning)) + + ;; hl line + (hl-line (:background ,weakest)) + (highlight-current-line-face (:inherit hl-line)) + + ;; ido + (ido-first-match (:bold t)) + (ido-only-match (:bold t)) + (ido-subdir (:italic t)) + (ido-virtual (:foreground ,weak)) + (ido-vertical-match-face (:bold t :italic nil)) + + ;; org mode + (org-table (:foreground ,weak)) + + )))) + + +(defun almost-mono-themes--variant-name (variant) + "Create symbol for color theme variant VARIANT." + (intern (format "almost-mono-%s" (symbol-name variant)))) + +(defmacro almost-mono-themes--define-theme (variant) + "Define a theme for the almost-mono variant VARIANT." + (let ((name (almost-mono-themes--variant-name variant)) + (doc (format "almost mono theme (%s version)" variant))) + `(progn + (deftheme ,name ,doc) + (put ',name 'theme-immediate t) + (almost-mono-themes--variant-with-colors + ',variant + (apply 'custom-theme-set-faces ',name + (almost-mono-themes--faces-spec))) + (provide-theme ',name)))) + +;;;###autoload +(when (and (boundp 'custom-theme-load-path) load-file-name) + (add-to-list 'custom-theme-load-path + (file-name-as-directory (file-name-directory load-file-name)))) + +(provide 'almost-mono-themes) + +;;; almost-mono-themes.el ends here diff --git a/home/dots/.emacs.d/elisp/exwm-mff.el b/home/dots/.emacs.d/elisp/exwm-mff.el new file mode 100644 index 0000000..6b1ef87 --- /dev/null +++ b/home/dots/.emacs.d/elisp/exwm-mff.el @@ -0,0 +1,191 @@ +;;; exwm-mff.el --- Mouse Follows Focus -*- lexical-binding: t; -*- + +;; Copyright (C) 2019, 2020, 2021 Ian Eure + +;; Author: Ian Eure +;; URL: https://github.com/ieure/exwm-mff +;; Version: 1.2.1 +;; Package-Requires: ((emacs "25.1")) +;; Keywords: unix + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program 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 General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; Mouse Follows Focus +;; =================== +;; +;; Traditional window managers are mouse-centric: the window to receive +;; input is usually selected with the pointing device. +;; +;; Emacs is keybord-centric: the window to receive key input is usually +;; selected with the keyboard. When you use the keyboard to focus a +;; window, the spatial relationship between pointer and active window is +;; broken -- the pointer can be anywhere on the screen, instead of over +;; the active window, which can make it hard to find. +;; +;; The same problem also exists in traditional windowing systems when +;; you use the keyboard to switch windows, e.g. with Alt-Tab. +;; +;; Because Emacs’ model is inverted, this suggests that the correct +;; behavior is also the inverse -- instead of using the mouse to +;; select a window to receive keyboard input, the keyboard should be +;; used to select the window to receive mouse input. +;; +;; `EXWM-MFF-MODE' is a global minor mode which does exactly this. +;; When the selected window in Emacs changes, the mouse pointer is +;; moved to its center, unless the pointer is already somewhere inside +;; the window’s bounds. While it's especially helpful for for EXWM +;; users, it works for any Emacs window in a graphical session. +;; +;; This package also offers the `EXWM-MFF-WARP-TO-SELECTED' command, +;; which allows you to summon the pointer with a hotkey. Unlike the +;; minor mode, summoning is unconditional, and will place the pointer in +;; the center of the window even if it already resides within its bounds +;; -- a handy feature if you’ve lost your pointer, even if you’re using +;; the minor mode. +;; +;; +;; Limitations +;; ~~~~~~~~~~~ +;; +;; None known at this time. + +;;; Code: + +(require 'subr-x) +(require 'cl-macs) + +(defcustom exwm-mff-ignore-if nil + "List of predicate functions for windows to ignore. + +Predicates accept one argument, WINDOW, and return non-NIL if +automatic pointer warping should be suppressed." + :type 'hook + :group 'exwm-mff) + +(defconst exwm-mff--debug-buffer " *exwm-mff-debug*" + "Name of the buffer exwm-mff will write debug messages into.") + +(defvar exwm-mff--debug 0 + "Whether (and how) to debug exwm-mff. +0 = don't debug. +1 = log messages to *exwm-mff-debug*. +2 = log messages to *exwm-mff-debug* and the echo area.") + +(defvar exwm-mff--last-window nil + "The last selected window.") + +(defun exwm-mff--guard () + "Raise an error unless this is a graphic session with mouse support." + (unless (and (display-graphic-p) (display-mouse-p)) + (error "EXWM-MFF-MODE doesn't work on non-graphic or non-mouse sessions"))) + +(defun exwm-mff--contains-pointer? (window) + "Return non-NIL when the mouse pointer is within FRAME and WINDOW." + (cl-destructuring-bind ((mouse-x . mouse-y) (left top right bottom)) + (list (mouse-absolute-pixel-position) + (window-absolute-pixel-edges window)) + (and (<= left mouse-x right) + (<= top mouse-y bottom)))) + +(defun exwm-mff--debug (string &rest objects) + "Log debug message STRING, using OBJECTS to format it." + (let ((debug-level (or exwm-mff--debug 0))) + (when (> debug-level 0) + (let ((str (apply #'format (concat "[%s] " string) + (cons (current-time-string) objects)))) + (when (>= debug-level 1) + (with-current-buffer (get-buffer-create exwm-mff--debug-buffer) + (goto-char (point-max)) + (insert (concat str "\n"))) + (when (>= debug-level 2) + (message str))))))) + +(defun exwm-mff-show-debug () + "Enable exwm-mff debugging, and show the buffer with debug logs." + (interactive) + (setq exwm-mff--debug 1) + (pop-to-buffer (get-buffer-create exwm-mff--debug-buffer))) + +(defun exwm-mff--window-center (window) + "Return a list of (x y) coordinates of the center of WINDOW in FRAME." + (cl-destructuring-bind (left top right bottom) (window-pixel-edges window) + (list (+ left (/ (- right left) 2)) + (+ top (/ (- bottom top) 2))))) + +(defun exwm-mff-warp-to (frame window) + "Place the pointer in the center of WINDOW in FRAME." + (apply #'set-mouse-pixel-position frame + (exwm-mff--window-center window))) + +;;;###autoload +(defun exwm-mff-warp-to-selected () + "Place the pointer in the center of the selected window." + (interactive) + (exwm-mff--guard) + (exwm-mff-warp-to (selected-frame) (selected-window))) + +(defun exwm-mff--explain (selected-window same-window? contains-pointer? mini? ignored?) + "Use SELECTED-WINDOW, SAME-WINDOW?, CONTAINS-POINTER?, MINI? +and IGNORED? to return an explanation of focusing behavior." + (cond + (same-window? "selected window hasn't changed") + (contains-pointer? "already contains pointer") + (mini? "is minibuffer") + (ignored? "one or more functions in `exwm-mff-ignore-if' matches") + (t (format "doesn't contain pointer (in %s)" selected-window)))) + +(defun exwm-mff-hook (sw &optional norecord) + "EXWM-MFF-MODE hook. + +This is after-advice placed on SELECT-WINDOW. It moves the +pointer to SW (the currently selected window), if NORECORD is +nil, and if it's not already in it." + (unless norecord + (if-let ((same-window? (eq sw exwm-mff--last-window))) + ;; The selected window is unchanged, we don't need to check + ;; anything else. + (exwm-mff--debug + "nop-> %s" (exwm-mff--explain sw same-window? nil nil nil)) + + (let* ((sf (window-frame sw)) + (contains-pointer? (exwm-mff--contains-pointer? sw)) + (mini? (minibufferp (window-buffer sw))) + (ignore? (run-hook-with-args-until-success 'exwm-mff-ignore-if sw))) + (if (or same-window? contains-pointer? mini? ignore?) + (exwm-mff--debug + "nop-> %s::%s (%s)" sf sw (exwm-mff--explain sw nil contains-pointer? mini? ignore?)) + (exwm-mff--debug + "warp-> %s::%s (%s)" sf sw (exwm-mff--explain sw nil contains-pointer? mini? ignore?)) + (exwm-mff-warp-to sf (setq exwm-mff--last-window sw))))))) + +(defgroup exwm-mff nil + "Mouse-Follows-Focus mode for EXWM." + :group 'exwm) + +;;;###autoload +(define-minor-mode exwm-mff-mode + "Mouse follows focus mode for EXWM." + :global t + :require 'exwm-mff + :group 'exwm-mff + (exwm-mff--guard) + (if exwm-mff-mode + (advice-add 'select-window :after #'exwm-mff-hook) + (advice-remove 'select-window #'exwm-mff-hook))) + +(provide 'exwm-mff) + +;;; exwm-mff.el ends here diff --git a/home/dots/.emacs.d/elisp/org-link-minor-mode.el b/home/dots/.emacs.d/elisp/org-link-minor-mode.el new file mode 100644 index 0000000..7f1faaa --- /dev/null +++ b/home/dots/.emacs.d/elisp/org-link-minor-mode.el @@ -0,0 +1,137 @@ +;;; org-link-minor-mode.el --- Enable org-mode links in non-org modes -*- lexical-binding: t; -*- +;; +;; Copyright (C) 2012-2020 +;; +;; Author: Sean O'Halpin +;; Maintainer: Sean O'Halpin +;; Created: 20120825 +;; Modified: 20200129 +;; Version: 0.0.3 +;; Package-Requires: ((emacs "24.3")) +;; Package-Version: 20200129.0141 +;; Keywords: hypermedia +;; Url: https://github.com/seanohalpin/org-link-minor-mode +;; +;; Changes for org v9: Stefan-W. Hahn +;; +;; This file is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. +;; +;; This file 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 General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . +;; +;;; Commentary: +;; +;; Enables org-mode links of the form: +;; +;; http://www.bbc.co.uk +;; man:emacs +;; info:emacs +;; +;; [[http://www.bbc.co.uk][BBC]] +;; [[org-link-minor-mode]] +;; [2012-08-18] +;; <2012-08-18> +;; +;; Note that `org-toggle-link-display' will also work when this mode +;; is enabled. +;; +;;; Code: + +(require 'org-element) + +;; Following declarations are necessary to make the byte compiler happy. + +;; For org v8 compatibility (if used with org v9) +(declare-function org-activate-plain-links "org" (limit)) +(declare-function org-activate-angle-links "org" (limit)) +(declare-function org-activate-bracket-links "org" (limit)) +(declare-function org-decompose-region "org-compat" (beg end)) + +;; For org v9 compatibility (if used with org v8) +(declare-function org-activate-links "org" (limit)) +(declare-function org-activate-dates "org" (limit)) + +(defun org-link-minor-mode--unfontify-region (beg end) + "Remove org-link fontification between BEG and END." + (font-lock-default-unfontify-region beg end) + (let* ((buffer-undo-list t) + (inhibit-read-only t) (inhibit-point-motion-hooks t) + (inhibit-modification-hooks t) + deactivate-mark buffer-file-name buffer-file-truename) + (if (fboundp 'org-decompose-region) + (org-decompose-region beg end) + (decompose-region beg end)) + (remove-text-properties beg end + '(mouse-face t keymap t org-linked-text t + invisible t intangible t + help-echo t rear-nonsticky t + htmlize-link t + org-no-flyspell t org-emphasis t)) + (org-remove-font-lock-display-properties beg end))) + +(defvar org-link-minor-mode-map (make-sparse-keymap) + "Local keymap.") +(make-variable-buffer-local 'org-link-minor-mode-map) + +;;;###autoload +(define-minor-mode org-link-minor-mode + "Toggle display of org-mode style links in non-org-mode buffers." + :lighter " org-link" + :keymap org-link-minor-mode-map + (let ((lk org-highlight-links) + org-link-minor-mode-keywords) + (if (fboundp 'org-activate-links) + ;; from Org v9.2 + (setq org-link-minor-mode-keywords + (list + '(org-activate-links) + (when (memq 'tag lk) '(org-activate-tags (1 'org-tag prepend))) + (when (memq 'radio lk) '(org-activate-target-links (1 'org-link t))) + (when (memq 'date lk) '(org-activate-dates (0 'org-date t))) + (when (memq 'footnote lk) '(org-activate-footnote-links)))) + (setq org-link-minor-mode-keywords + (list + (when (memq 'tag lk) '(org-activate-tags (1 'org-tag prepend))) + (when (memq 'angle lk) '(org-activate-angle-links (0 'org-link t))) + (when (memq 'plain lk) '(org-activate-plain-links (0 'org-link t))) + (when (memq 'bracket lk) '(org-activate-bracket-links (0 'org-link t))) + (when (memq 'radio lk) '(org-activate-target-links (0 'org-link t))) + (when (memq 'date lk) '(org-activate-dates (0 'org-date t))) + (when (memq 'footnote lk) '(org-activate-footnote-links))))) + (if org-link-minor-mode + (if (derived-mode-p 'org-mode) + (progn + (message "org-mode doesn't need org-link-minor-mode") + (org-link-minor-mode -1)) + (font-lock-add-keywords nil org-link-minor-mode-keywords t) + (kill-local-variable 'org-mouse-map) + (setq-local org-mouse-map + (let ((map (make-sparse-keymap))) + (define-key map [return] 'org-open-at-point) + (define-key map [tab] 'org-next-link) + (define-key map [backtab] 'org-previous-link) + (define-key map [mouse-2] 'org-open-at-point) + (define-key map [follow-link] 'mouse-face) + map)) + (setq-local font-lock-unfontify-region-function + 'org-link-minor-mode--unfontify-region) + (setq-local org-descriptive-links nil) + (org-toggle-link-display)) + (unless (derived-mode-p 'org-mode) + (font-lock-remove-keywords nil org-link-minor-mode-keywords) + (setq org-descriptive-links t) + (org-toggle-link-display) + (kill-local-variable 'org-descriptive-links) + (kill-local-variable 'org-mouse-map) + (kill-local-variable 'font-lock-unfontify-region-function))))) + +(provide 'org-link-minor-mode) +;;; org-link-minor-mode.el ends here -- cgit v1.2.3