Add current doom config

This commit is contained in:
2025-04-12 09:42:15 +02:00
commit e1266f5057
6 changed files with 2421 additions and 0 deletions

379
config.el Normal file
View File

@@ -0,0 +1,379 @@
;;; $DOOMDIR/config.el -*- lexical-binding: t; -*-
;; Place your private configuration here! Remember, you do not need to run 'doom
;; sync' after modifying this file!
;; Some functionality uses this to identify you, e.g. GPG configuration, email
;; clients, file templates and snippets. It is optional.
;; (setq user-full-name "John Doe"
;; user-mail-address "john@doe.com")
;; Doom exposes five (optional) variables for controlling fonts in Doom:
;;
;; - `doom-font' -- the primary font to use
;; - `doom-variable-pitch-font' -- a non-monospace font (where applicable)
;; - `doom-big-font' -- used for `doom-big-font-mode'; use this for
;; presentations or streaming.
;; - `doom-symbol-font' -- for symbols
;; - `doom-serif-font' -- for the `fixed-pitch-serif' face
;;
;; See 'C-h v doom-font' for documentation and more examples of what they
;; accept. For example:
;;
;;(setq doom-font (font-spec :family "Fira Code" :size 12 :weight 'semi-light)
;; doom-variable-pitch-font (font-spec :family "Fira Sans" :size 13))
;;
;; If you or Emacs can't find your font, use 'M-x describe-font' to look them
;; up, `M-x eval-region' to execute elisp code, and 'M-x doom/reload-font' to
;; refresh your font settings. If Emacs still can't find your font, it likely
;; wasn't installed correctly. Font issues are rarely Doom issues!
;; There are two ways to load a theme. Both assume the theme is installed and
;; available. You can either set `doom-theme' or manually load a theme with the
;; `load-theme' function. This is the default:
(setq doom-theme 'doom-one)
;;(load-theme 'catppuccin :no-confirm)
;; This determines the style of line numbers in effect. If set to `nil', line
;; numbers are disabled. For relative line numbers, set this to `relative'.
(setq display-line-numbers-type t)
;; If you use `org' and don't want your org files in the default location below,
;; change `org-directory'. It must be set before org loads!
(setq org-directory "~/Documents/Org")
(setq org-roam-directory (file-truename "~/Documents/Org/roam")) ;; Set the directory for your notes
;;(setq doom-font (font-spec :family "Roboto Mono" :size 13))
(when (member "Roboto Mono" (font-family-list))
(set-face-attribute 'default nil :font "Roboto Mono" :height 110)
(set-face-attribute 'fixed-pitch nil :family "Roboto Mono"))
(when (member "Source Sans 3" (font-family-list))
(set-face-attribute 'variable-pitch nil :family "Source Sans 3" :height 1.25))
;; Whenever you reconfigure a package, make sure to wrap your config in an
;; `after!' block, otherwise Doom's defaults may override your settings. E.g.
;;
;; (after! PACKAGE
;; (setq x y))
;;
;; The exceptions to this rule:
;;
;; - Setting file/directory variables (like `org-directory')
;; - Setting variables which explicitly tell you to set them before their
;; package is loaded (see 'C-h v VARIABLE' to look up their documentation).
;; - Setting doom variables (which start with 'doom-' or '+').
;;
;; Here are some additional functions/macros that will help you configure Doom.
;;
;; - `load!' for loading external *.el files relative to this one
;; - `use-package!' for configuring packages
;; - `after!' for running code after a package has loaded
;; - `add-load-path!' for adding directories to the `load-path', relative to
;; this file. Emacs searches the `load-path' when you load packages with
;; `require' or `use-package'.
;; - `map!' for binding new keys
;;
;; To get information about any of these functions/macros, move the cursor over
;; the highlighted symbol at press 'K' (non-evil users must press 'C-c c k').
;; This will open documentation for it, including demos of how they are used.
;; Alternatively, use `C-h o' to look up a symbol (functions, variables, faces,
;; etc).
;;
;; You can also try 'gd' (or 'C-c c d') to jump to their definition and see how
;; they are implemented.
;;
(use-package! copilot
:hook (prog-mode . copilot-mode)
:bind (:map copilot-completion-map
("<tab>" . 'copilot-accept-completion)
("TAB" . 'copilot-accept-completion)
("C-TAB" . 'copilot-accept-completion-by-word)
("C-<tab>" . 'copilot-accept-completion-by-word)
("C-n" . 'copilot-next-completion)
("C-p" . 'copilot-previous-completion))
:config
(add-to-list 'copilot-indentation-alist '(prog-mode 2))
(add-to-list 'copilot-indentation-alist '(org-mode 2))
(add-to-list 'copilot-indentation-alist '(text-mode 2))
(add-to-list 'copilot-indentation-alist '(closure-mode 2))
(add-to-list 'copilot-indentation-alist '(emacs-lisp-mode 2)))
;; ==============================================================
;; Shortcuts
;; ==============================================================
;; check OS type
(cond
((string-equal system-type "windows-nt") ; Microsoft Windows
(progn
(message "Microsoft Windows")))
((string-equal system-type "darwin") ; Mac OS X
(progn
(setq mac-option-key-is-meta nil)
(setq mac-command-key-is-meta t)
(setq mac-command-modifier 'meta)
(setq mac-option-modifier nil)
(message "Mac OS X")))
((string-equal system-type "gnu/linux") ; linux
(progn
(message "Linux"))))
;; Copy to system clipboard with M-c
(global-set-key (kbd "M-c") 'clipboard-kill-ring-save)
;; Paste from system clipboard with M-v
(global-set-key (kbd "M-v") 'clipboard-yank)
;; Zoom in with C-+
(global-set-key (kbd "C-=") 'text-scale-increase)
;; Zoom out with C--
(global-set-key (kbd "C--") 'text-scale-decrease)
;; Scroll up one screen with C-S-v
(global-set-key (kbd "C-S-v") 'scroll-down-command)
;; Select next occurences of a word
(global-set-key (kbd "C-d") 'mc/mark-next-like-this-symbol)
;; ==============================================================
;; Coq
;; ==============================================================
(add-hook 'coq-mode-hook #'company-coq-mode)
(add-hook 'coq-mode-hook (lambda () (local-set-key (kbd "C-<down>") #'proof-assert-next-command-interactive)))
(add-hook 'coq-mode-hook (lambda () (local-set-key (kbd "C-<up>") #'proof-retract-until-point-interactive)))
;;==============================================================
;; Org mode
;; =============================================================
(use-package vulpea
:ensure t
;; hook into org-roam-db-autosync-mode you wish to enable
;; persistence of meta values (see respective section in README to
;; find out what meta means)
:hook ((org-roam-db-autosync-mode . vulpea-db-autosync-enable)))
;; ================== Appearance ==================
;; Improve org mode looks
(use-package org-indent)
(set-face-attribute 'org-indent nil :inherit '(org-hide fixed-pitch))
(use-package olivetti)
(use-package org-appear
:hook
(org-mode . org-appear-mode))
(use-package! org-modern
:hook
(org-mode . global-org-modern-mode)
:config
(setq
org-auto-align-tags t
org-tags-column 0
org-fold-catch-invisible-edits 'show-and-error
org-special-ctrl-a/e t
org-insert-heading-respect-content t
;; Don't style the following
org-modern-tag nil
org-modern-todo nil
org-modern-priority nil)
(global-org-modern-mode))
;; Resize Org headings
(dolist (face '((org-level-1 . 1.4)
(org-level-2 . 1.3)
(org-level-3 . 1.2)
(org-level-4 . 1.1)
(org-level-5 . 1.1)
(org-level-6 . 1.1)
(org-level-7 . 1.1)
(org-level-8 . 1.1)))
(set-face-attribute (car face) nil :family "Source Sans 3" :weight 'bold :height (cdr face)))
;; Make the document title a bit bigger
(set-face-attribute 'org-document-title nil
:family "Source Sans 3"
:weight 'bold
:height 1.8)
(add-hook 'org-mode-hook 'variable-pitch-mode)
(add-hook 'org-mode-hook 'visual-line-mode)
(add-hook 'org-mode-hook (lambda () (display-line-numbers-mode 0)))
(set-face-attribute 'org-block nil :foreground nil :inherit
'fixed-pitch :height 0.85)
(set-face-attribute 'org-code nil :inherit '(shadow fixed-pitch) :height 0.85)
(set-face-attribute 'org-indent nil :inherit '(org-hide fixed-pitch) :height 0.85)
(set-face-attribute 'org-verbatim nil :inherit '(shadow fixed-pitch) :height 0.85)
(set-face-attribute 'org-special-keyword nil :inherit '(font-lock-comment-face
fixed-pitch))
(set-face-attribute 'org-meta-line nil :inherit '(font-lock-comment-face fixed-pitch))
(set-face-attribute 'org-checkbox nil :inherit 'fixed-pitch)
(set-face-attribute 'org-table nil :inherit 'fixed-pitch)
(plist-put org-format-latex-options :scale 2)
;; Use major mode of a specific language in an SRC block
(setq org-src-fontify-natively t
org-src-tab-acts-natively t
org-edit-src-content-indentation 0)
(add-hook 'org-mode-hook 'olivetti-mode)
;; ORG TODO
(setq org-lowest-priority ?F) ;; Gives us priorities A through F
(setq org-default-priority ?E) ;; If an item has no priority, it is considered [#E].
(setq org-priority-faces
'((65 . "#BF616A")
(66 . "#EBCB8B")
(67 . "#B48EAD")
(68 . "#81A1C1")
(69 . "#5E81AC")
(70 . "#4C566A")))
(setq org-todo-keywords
'((sequence
"TODO" "PROJ" "READ" "CHECK" "IDEA" ; Needs further action
"|"
"DONE"))) ; Needs no action currently
(setq org-todo-keyword-faces
'(("TODO" :inherit (org-todo region) :foreground "#A3BE8C" :weight bold)
("PROJ" :inherit (org-todo region) :foreground "#88C0D0" :weight bold)
("READ" :inherit (org-todo region) :foreground "#8FBCBB" :weight bold)
("CHECK" :inherit (org-todo region) :foreground "#81A1C1" :weight bold)
("IDEA" :inherit (org-todo region) :foreground "#EBCB8B" :weight bold)
("DONE" :inherit (org-todo region) :foreground "#30343d" :weight bold)))
(setq org-startup-indented t
org-pretty-entities t
org-use-sub-superscripts "{}"
org-hide-emphasis-markers t
org-startup-with-inline-images t
org-image-actual-width '(300))
(setq org-support-shift-select t)
(add-to-list 'load-path "~/.doom.d/")
(setq org-startup-truncated nil)
(with-eval-after-load "org"
(require 'org-phscroll))
;; ================== ORG Roam ==================
(use-package! org-roam
:config
(org-roam-db-autosync-mode)) ;; Automatically sync the roam database
(setq org-roam-completion-everywhere t) ;; Enable Org-roam completions globally
(setq org-roam-mode-sections
'(org-roam-backlinks-section ;; Show backlinks
org-roam-reflinks-section ;; Show references (if applicable)
org-roam-unlinked-references-section)) ;; Show unlinked references
;; ================== Shortcuts ==================
(global-set-key (kbd "C-o") 'org-open-at-point)
(global-set-key (kbd "M-o") 'org-mark-ring-goto)
;; Insert a not without opening it
(defun org-roam-node-insert-immediate (arg &rest args)
(interactive "P")
(let ((args (cons arg args))
(org-roam-capture-templates (list (append (car org-roam-capture-templates)
'(:immediate-finish t)))))
(apply #'org-roam-node-insert args)))
(global-set-key (kbd "C-c n r I") 'org-roam-node-insert-immediate)
;;paste image from clipboard
(use-package! org-download)
(setq org-download-image-dir "images")
(after! org-download
(setq org-download-method 'directory))
(setq org-download-heading-lvl nil)
(setq org-download-timestamp "%Y%m%d-%H%M%S_")
(setq org-image-actual-width 300)
(map! :map org-mode-map
"C-c n r v" 'org-download-clipboard)
;; ================== Agenda ==================
;; Auto add roam file with TODO to the agenda
(defun vulpea-project-p ()
"Return non-nil if current buffer has any todo entry.
TODO entries marked as done are ignored, meaning the this
function returns nil if current buffer contains only completed
tasks."
(seq-find ; (3)
(lambda (type)
(eq type 'todo))
(org-element-map ; (2)
(org-element-parse-buffer 'headline) ; (1)
'headline
(lambda (h)
(org-element-property :todo-type h)))))
(defun vulpea-project-update-tag ()
"Update PROJECT tag in the current buffer."
(when (and (not (active-minibuffer-window))
(vulpea-buffer-p))
(save-excursion
(goto-char (point-min))
(let* ((tags (vulpea-buffer-tags-get))
(original-tags tags))
(if (vulpea-project-p)
(setq tags (cons "project" tags))
(setq tags (remove "project" tags)))
;; cleanup duplicates
(setq tags (seq-uniq tags))
;; update tags if changed
(when (or (seq-difference tags original-tags)
(seq-difference original-tags tags))
(apply #'vulpea-buffer-tags-set tags))))))
(defun vulpea-buffer-p ()
"Return non-nil if the currently visited buffer is a note."
(and buffer-file-name
(string-prefix-p
(expand-file-name (file-name-as-directory org-roam-directory))
(file-name-directory buffer-file-name))))
(defun vulpea-project-files ()
"Return a list of note files containing 'project' tag." ;
(seq-uniq
(seq-map
#'car
(org-roam-db-query
[:select [nodes:file]
:from tags
:left-join nodes
:on (= tags:node-id nodes:id)
:where (like tag (quote "%\"project\"%"))]))))
(defun vulpea-agenda-files-update (&rest _)
"Update the value of `org-agenda-files'."
(setq org-agenda-files (vulpea-project-files)))
(add-hook 'find-file-hook #'vulpea-project-update-tag)
(add-hook 'before-save-hook #'vulpea-project-update-tag)
(advice-add 'org-agenda :before #'vulpea-agenda-files-update)
(advice-add 'org-todo-list :before #'vulpea-agenda-files-update)

13
custom.el Normal file
View File

@@ -0,0 +1,13 @@
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(package-selected-packages
'(catppuccin-theme obsidian olivetti org-download org-superstar vulpea)))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)

194
init.el Normal file
View File

@@ -0,0 +1,194 @@
;;; init.el -*- lexical-binding: t; -*-
;; This file controls what Doom modules are enabled and what order they load
;; in. Remember to run 'doom sync' after modifying it!
;; NOTE Press 'SPC h d h' (or 'C-h d h' for non-vim users) to access Doom's
;; documentation. There you'll find a link to Doom's Module Index where all
;; of our modules are listed, including what flags they support.
;; NOTE Move your cursor over a module's name (or its flags) and press 'K' (or
;; 'C-c c k' for non-vim users) to view its documentation. This works on
;; flags as well (those symbols that start with a plus).
;;
;; Alternatively, press 'gd' (or 'C-c c d') on a module to browse its
;; directory (for easy access to its source code).
(doom! :input
;;bidi ; (tfel ot) thgir etirw uoy gnipleh
;;chinese
;;japanese
;;layout ; auie,ctsrnm is the superior home row
:completion
company ; the ultimate code completion backend
;;(corfu +orderless) ; complete with cap(f), cape and a flying feather!
;;helm ; the *other* search engine for love and life
;;ido ; the other *other* search engine...
;;ivy ; a search engine for love and life
vertico ; the search engine of the future
:ui
;;deft ; notational velocity for Emacs
doom ; what makes DOOM look the way it does
doom-dashboard ; a nifty splash screen for Emacs
;;doom-quit ; DOOM quit-message prompts when you quit Emacs
(emoji +unicode) ; 🙂
hl-todo ; highlight TODO/FIXME/NOTE/DEPRECATED/HACK/REVIEW
;;indent-guides ; highlighted indent columns
ligatures ; ligatures and symbols to make your code pretty again
minimap ; show a map of the code on the side
modeline ; snazzy, Atom-inspired modeline, plus API
;;nav-flash ; blink cursor line after big motions
;;neotree ; a project drawer, like NERDTree for vim
ophints ; highlight the region an operation acts on
(popup +defaults) ; tame sudden yet inevitable temporary windows
;;tabs ; a tab bar for Emacs
treemacs ; a project drawer, like neotree but cooler
unicode ; extended unicode support for various languages
(vc-gutter +pretty) ; vcs diff in the fringe
vi-tilde-fringe ; fringe tildes to mark beyond EOB
window-select ; visually switch windows
workspaces ; tab emulation, persistence & separate workspaces
;;zen ; distraction-free coding or writing
:editor
;;(evil +everywhere); come to the dark side, we have cookies
file-templates ; auto-snippets for empty files
fold ; (nigh) universal code folding
(format +onsave) ; automated prettiness
;;god ; run Emacs commands without modifier keys
;;lispy ; vim for lisp, for people who don't like vim
multiple-cursors ; editing in many places at once
;;objed ; text object editing for the innocent
;;parinfer ; turn lisp into python, sort of
;;rotate-text ; cycle region at point between text candidates
snippets ; my elves. They type so I don't have to
;;word-wrap ; soft wrapping with language-aware indent
:emacs
dired ; making dired pretty [functional]
electric ; smarter, keyword-based electric-indent
;;eww ; the internet is gross
ibuffer ; interactive buffer management
undo ; persistent, smarter undo for your inevitable mistakes
vc ; version-control and Emacs, sitting in a tree
:term
;;eshell ; the elisp shell that works everywhere
;;shell ; simple shell REPL for Emacs
;;term ; basic terminal emulator for Emacs
vterm ; the best terminal emulation in Emacs
:checkers
syntax ; tasing you for every semicolon you forget
(spell +flyspell) ; tasing you for misspelling mispelling
grammar ; tasing grammar mistake every you make
:tools
;;ansible
;;biblio ; Writes a PhD for you (citation needed)
;;collab ; buffers with friends
debugger ; FIXME stepping through code, to help you add bugs
direnv
docker
;;editorconfig ; let someone else argue about tabs vs spaces
;;ein ; tame Jupyter notebooks with emacs
(eval +overlay) ; run code, run (also, repls)
lookup ; navigate your code and its documentation
lsp ; M-x vscode
magit ; a git porcelain for Emacs
make ; run make tasks from Emacs
;;pass ; password manager for nerds
pdf ; pdf enhancements
;;prodigy ; FIXME managing external services & code builders
;;terraform ; infrastructure as code
;;tmux ; an API for interacting with tmux
;;tree-sitter ; syntax and parsing, sitting in a tree...
;;upload ; map local to remote projects via ssh/ftp
:os
(:if (featurep :system 'macos) macos) ; improve compatibility with macOS
;;tty ; improve the terminal Emacs experience
:lang
;;agda ; types of types of types of types...
;;beancount ; mind the GAAP
(cc +lsp) ; C > C++ == 1
;;clojure ; java with a lisp
;;common-lisp ; if you've seen one lisp, you've seen them all
coq ; proofs-as-programs
;;crystal ; ruby at the speed of c
;;csharp ; unity, .NET, and mono shenanigans
data ; config/data formats
;;(dart +flutter) ; paint ui and not much else
;;dhall
;;elixir ; erlang done right
;;elm ; care for a cup of TEA?
emacs-lisp ; drown in parentheses
;;erlang ; an elegant language for a more civilized age
;;ess ; emacs speaks statistics
;;factor
;;faust ; dsp, but you get to keep your soul
;;fortran ; in FORTRAN, GOD is REAL (unless declared INTEGER)
;;fsharp ; ML stands for Microsoft's Language
;;fstar ; (dependent) types and (monadic) effects and Z3
;;gdscript ; the language you waited for
;;(go +lsp) ; the hipster dialect
;;(graphql +lsp) ; Give queries a REST
;;(haskell +lsp) ; a language that's lazier than I am
;;hy ; readability of scheme w/ speed of python
;;idris ; a language you can depend on
json ; At least it ain't XML
(java +lsp) ; the poster child for carpal tunnel syndrome
;;javascript ; all(hope(abandon(ye(who(enter(here))))))
;;julia ; a better, faster MATLAB
;;kotlin ; a better, slicker Java(Script)
;;latex ; writing papers in Emacs has never been so fun
;;lean ; for folks with too much to prove
;;ledger ; be audit you can be
;;lua ; one-based indices? one-based indices
markdown ; writing docs for people to ignore
;;nim ; python + lisp at the speed of c
nix ; I hereby declare "nix geht mehr!"
;;ocaml ; an objective camel
(org +roam2) ; organize your plain life in plain text
;;php ; perl's insecure younger brother
;;plantuml ; diagrams for confusing people more
;;graphviz ; diagrams for confusing yourself even more
;;purescript ; javascript, but functional
python ; beautiful is better than ugly
;;qt ; the 'cutest' gui framework ever
;;racket ; a DSL for DSLs
;;raku ; the artist formerly known as perl6
;;rest ; Emacs as a REST client
;;rst ; ReST in peace
;;(ruby +rails) ; 1.step {|i| p "Ruby is #{i.even? ? 'love' : 'life'}"}
(rust +lsp) ; Fe2O3.unwrap().unwrap().unwrap().unwrap()
;;scala ; java, but good
;;(scheme +guile) ; a fully conniving family of lisps
sh ; she sells {ba,z,fi}sh shells on the C xor
;;sml
;;solidity ; do you need a blockchain? No.
;;swift ; who asked for emoji variables?
;;terra ; Earth and Moon in alignment for performance.
;;web ; the tubes
yaml ; JSON, but readable
;;zig ; C, but simpler
:email
;;(mu4e +org +gmail)
;;notmuch
;;(wanderlust +gmail)
:app
;;calendar
;;emms
;;everywhere ; *leave* Emacs!? You must be joking
;;irc ; how neckbeards socialize
;;(rss +org) ; emacs as an RSS reader
:config
;;literate
(default +bindings +smartparens))

352
org-phscroll.el Normal file
View File

@@ -0,0 +1,352 @@
;;; org-phscroll.el --- Apply horizontal scroll to org-mode table -*- lexical-binding: t; -*-
;; Copyright (C) 2020 AKIYAMA Kouhei
;; Author: AKIYAMA Kouhei
;; Keywords:
;; 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 <https://www.gnu.org/licenses/>.
;;; Commentary:
;;; Enable wide table horizontal scrolling even if org-startup-truncated is nil.
;;; Usage:
;;; (load "org-phscroll.el")
;;; Code:
(require 'org)
(require 'phscroll)
(defvar org-phscroll-buffer-name-regexp-to-disable
'(;; see: org-src-font-lock-fontify-block in org-src.el
"\\` *\\*org-src-fontification:.*\\*\\'"
;; see: org-html-fontify-code in ox-html.el
"\\` *\\*temp\\*-[0-9]+\\'"))
(defvar-local org-phscroll-disabled nil)
(defvar-local org-phscroll-font-lock-keywords (list '(org-phscroll--fontify)))
;;;###autoload
(define-minor-mode org-phscroll-mode
"Apply phscroll to org-table."
:type 'boolean
:init-value nil
:group 'org-phscroll
(if org-phscroll-mode
(progn
;; Do not anything in some buffers.
(setq-local org-phscroll-disabled
(not
(null
(seq-some
(lambda (regexp) (string-match-p regexp (buffer-name)))
org-phscroll-buffer-name-regexp-to-disable))))
;; (when org-phscroll-disabled
;; (message "Disable org-phscroll-mode in %s" (buffer-name)))
(unless org-phscroll-disabled
;; Do not update on modification-hooks. Update on font-lock.
(setq-local phscroll-update-area-display-on-modified nil)
(phscroll-mode 1)
(font-lock-add-keywords nil org-phscroll-font-lock-keywords t)
(font-lock-flush)))
(unless org-phscroll-disabled
(font-lock-remove-keywords nil org-phscroll-font-lock-keywords)
(setq-local phscroll-update-area-display-on-modified t)
(phscroll-delete-all) ;;@todo Keep manually added areas (Identify areas created by org-phscroll, and delete(remove-region) only areas created by org-phscroll when fontify)
(phscroll-mode -1))))
(defun org-phscroll--fontify (limit)
(when org-phscroll-mode
(save-match-data
(save-excursion
(save-restriction
(widen)
;; Invalidate areas that overlaps range to fontify.
;; Because the text width may have changed due to the
;; fontify of the previous keyword (for example, the
;; org-link value of the invisible property).
(phscroll-invalidate-region (point) limit)
;; Create/Delete/Move phscroll areas.
(goto-char (phscroll-line-begin))
(let* ((start (point))
;; ("|" or "+-[+-]") ... not whitespace
(table-re "^[ \t]*\\(\\(|\\|\\+-[-+]\\).*\\S-\\)")
;; [^|+]
;; +([^-] or $)
;; +-([^+-] or $)
;; +-[+-] whitespace...$
;; | whitespace...$
;; $
(not-table-re "^[ \t]*\\([^|+ \t]\\|\\+\\([^-]\\|$\\|-\\([^-+]\\|$\\|[-+]\\s-*$\\)\\)\\||\\s-*$\\|$\\)")
(phscroll-fontify-range (cons start limit))
not-table-beg)
;;(message "org-phscroll--fontify start=%s limit=%s line-end=%s" start limit (phscroll-line-end));;debug
(while (progn
(setq not-table-beg (point))
(and (< (point) limit)
(re-search-forward table-re limit t)))
(let* ((not-table-end (phscroll-line-begin))
(table-beg not-table-end)
(table-end (if (re-search-forward not-table-re limit t)
(goto-char (phscroll-line-begin (match-beginning 0))) ;; beginning of not table
(goto-char limit)))) ;; end of fontify
;; not table
(if (< not-table-beg not-table-end)
(phscroll-remove-region not-table-beg not-table-end))
;; table?
;; exclude comment, blocks
(if (or (text-property-any table-beg table-end 'face 'org-table)
(eq (car-safe (get-text-property table-beg 'face)) 'org-table)) ;; for org-modern (org-table (:overline) (:height 0.1))
;; table
(progn
;; include previous line if previous line is in area
(if (and (= start table-beg)
(phscroll-enum-area (phscroll-line-begin (1- start))
(phscroll-line-end (1- start))))
(setq table-beg (phscroll-line-begin (1- start))))
;; include next line if next line is in area
(if (phscroll-enum-area (phscroll-line-begin table-end)
(phscroll-line-end table-end))
(setq table-end (min (point-max)
(1+ (phscroll-line-end table-end)))))
;; cover single area
(phscroll-cover-region table-beg table-end))
;; not table
(phscroll-remove-region table-beg table-end))))
;; not table
(if (< not-table-beg limit)
(phscroll-remove-region not-table-beg limit))))))
nil))
;; (defun org-phscroll--font-lock-set-keywords ()
;; ;; See: org-set-font-lock-defaults
;; (nconc
;; org-font-lock-extra-keywords
;; (list
;; '(org-phscroll--fontify))))
;;;; Support for table column shrink/expand
(defun org-phscroll-invalidate-table (pos)
(when-let ((area (phscroll-get-area-at pos)))
(phscroll-area-clear-updated-ranges area)
;; @todo necessary?
;; (font-lock-unfontify-region
;; (phscroll-area-begin area)
;; (phscroll-area-end area))
))
(defun org-phscroll--table-shrink-columns (_columns beg _end &rest _)
(org-phscroll-invalidate-table beg))
(defun org-phscroll--table-expand (&optional beg _end &rest _)
(when (and (null beg)
(org-at-table-p))
(setq beg (org-table-begin)))
(when beg
(org-phscroll-invalidate-table beg)))
;;;; Support for org-table-overlay-coordinates
(defun org-phscroll--table-toggle-coordinate-overlays (&rest _)
(org-phscroll-invalidate-table (point)))
;;;; Support for org-table-header-line-mode
(defun org-phscroll--after-table-header-line-mode (&rest _)
;; Cancel post-command-hook.
;; Use phscroll's post-command-hook only.
(remove-hook 'post-command-hook #'org-table-header-set-header t))
(defun org-phscroll--table-row-get-visible-string (old-func &optional beg)
(unless beg
(setq beg (point)))
(let ((area (phscroll-get-area-at beg)))
(if (null area)
;; Call original
(funcall old-func beg)
;; In phscroll area
(save-excursion
;;@todo Is it possible to unify with around phscroll-char-width-next?
;;@todo Support more properties
(let ((pos (phscroll-line-begin beg))
(eol (phscroll-line-end beg))
visible-strs)
(while (< pos eol)
(let (next-pos pvalue)
;; Overlay
(let ((overlays (overlays-at pos t)))
(while (and overlays (null next-pos))
(let ((ov (car overlays)))
(unless (or (overlay-get ov 'phscroll)
(overlay-get ov 'phscroll-ignore))
(cond
;; Overlay's display
((setq pvalue (overlay-get ov 'display))
(when (stringp pvalue)
(push pvalue visible-strs))
(setq next-pos (overlay-end ov)))
;; Overlay's invisible
((and (setq pvalue (overlay-get ov 'invisible))
(invisible-p pvalue))
(setq next-pos (overlay-end ov))))))
(setq overlays (cdr overlays))))
;; Text property
(unless next-pos
(cond
;; Text's display
((setq pvalue (get-text-property pos 'display))
(cond
((stringp pvalue)
(push pvalue visible-strs))
((and (consp pvalue)
(eq (car pvalue) 'space)
(eq (cadr pvalue) :relative-width)
(integerp (caddr pvalue)))
(push (make-string (caddr pvalue) (char-after pos)) visible-strs)))
(setq next-pos
(next-single-property-change pos 'display nil eol)))
;; Text's invisible
((and (setq pvalue (get-text-property pos 'invisible))
(invisible-p pvalue))
(setq next-pos
(next-single-property-change pos 'invisible nil eol)))
;; Character
(t
(push (char-to-string (char-after pos)) visible-strs)
(setq next-pos (1+ pos)))))
(setq pos next-pos)))
(let* ((win-width (phscroll-window-width-at beg nil))
(scroll-column (phscroll-get-scroll-column area))
(visible-str (apply #'concat (nreverse visible-strs)))
(result (truncate-string-to-width
visible-str
(+ scroll-column win-width)
scroll-column ?\s)))
;;(message "result=%s" result)
result))))))
(defun org-phscroll--around-post-command-in-header-line-mode (old-func &rest args)
(if (and (boundp 'org-table-header-line-mode) ;; Org 9.4 or later
org-table-header-line-mode)
(progn
;; Delete overlay before phscroll process
(when (overlayp org-table-header-overlay)
(delete-overlay org-table-header-overlay)
(setq org-table-header-overlay nil))
;; Call phscroll process
(prog1 (apply old-func args)
;; Update header line
(ignore-errors
(org-table-header-set-header))
(when org-table-header-overlay
(overlay-put org-table-header-overlay 'phscroll-ignore t)
(overlay-put org-table-header-overlay 'priority 20)
(let ((win-start (overlay-start org-table-header-overlay)))
(move-overlay org-table-header-overlay
(phscroll-line-begin win-start)
(phscroll-line-end win-start))))))
;; Not in header line mode
(apply old-func args)))
;;;; Support for org-indent
(defun org-phscroll-invalidate-indent (beg end)
;;(message "invalidate %s %s" beg end)
(dolist (area (phscroll-enum-area beg end))
(phscroll-area-remove-updated-range beg end area)
;;(phscroll-area-clear-updated-ranges area)
))
(defun org-phscroll--indent-add-properties (beg end &optional _delay)
(org-phscroll-invalidate-indent beg end))
;;;; Hook global functions
;;;###autoload
(defun org-phscroll-activate ()
(interactive)
(add-hook 'org-mode-hook
#'org-phscroll-mode)
;; (add-hook 'org-font-lock-set-keywords-hook
;; #'org-phscroll--font-lock-set-keywords)
;; for table shrink/expand
(advice-add #'org-table--shrink-columns
:after #'org-phscroll--table-shrink-columns)
(advice-add #'org-table-expand
:after #'org-phscroll--table-expand)
;; for org-table-overlay-coordinates
(advice-add #'org-table-toggle-coordinate-overlays
:after #'org-phscroll--table-toggle-coordinate-overlays)
;; for org-table-header-line-mode
(advice-add #'org-table-header-line-mode
:after #'org-phscroll--after-table-header-line-mode)
(advice-add #'org-table-row-get-visible-string
:around #'org-phscroll--table-row-get-visible-string)
(advice-add #'phscroll-on-post-command
:around #'org-phscroll--around-post-command-in-header-line-mode)
;; for indent
(with-no-warnings ;;Some one not needs to (require 'org-indent)
(advice-add #'org-indent-add-properties
:after #'org-phscroll--indent-add-properties)))
;;;###autoload
(defun org-phscroll-deactivate ()
(interactive)
(remove-hook 'org-mode-hook
#'org-phscroll-mode)
;; (remove-hook 'org-font-lock-set-keywords-hook
;; #'org-phscroll--font-lock-set-keywords)
;; for table shrink/expand
(advice-remove #'org-table--shrink-columns
#'org-phscroll--table-shrink-columns)
(advice-remove #'org-table-expand
#'org-phscroll--table-expand)
;; for org-table-overlay-coordinates
(advice-remove #'org-table-toggle-coordinate-overlays
#'org-phscroll--table-toggle-coordinate-overlays)
;; for org-table-header-line-mode
(advice-remove #'org-table-header-line-mode
#'org-phscroll--after-table-header-line-mode)
(advice-remove #'org-table-row-get-visible-string
#'org-phscroll--table-row-get-visible-string)
(advice-remove #'phscroll-on-post-command
#'org-phscroll--around-post-command-in-header-line-mode)
;; for indent
(with-no-warnings ;;Some one not needs to (require 'org-indent)
(advice-remove #'org-indent-add-properties
#'org-phscroll--indent-add-properties)))
(with-eval-after-load "org"
(org-phscroll-activate))
(provide 'org-phscroll)
;;; org-phscroll.el ends here

57
packages.el Normal file
View File

@@ -0,0 +1,57 @@
;; -*- no-byte-compile: t; -*-
;;; $DOOMDIR/packages.el
;; To install a package with Doom you must declare them here and run 'doom sync'
;; on the command line, then restart Emacs for the changes to take effect -- or
;; To install SOME-PACKAGE from MELPA, ELPA or emacsmirror:
;; (package! some-package)
;; To install a package directly from a remote git repo, you must specify a
;; `:recipe'. You'll find documentation on what `:recipe' accepts here:
;; https://github.com/radian-software/straight.el#the-recipe-format
;; (package! another-package
;; :recipe (:host github :repo "username/repo"))
;; If the package you are trying to install does not contain a PACKAGENAME.el
;; file, or is located in a subdirectory of the repo, you'll need to specify
;; `:files' in the `:recipe':
;; (package! this-package
;; :recipe (:host github :repo "username/repo"
;; :files ("some-file.el" "src/lisp/*.el")))
;; If you'd like to disable a package included with Doom, you can do so here
;; with the `:disable' property:
;; (package! builtin-package :disable t)
;; You can override the recipe of a built in package without having to specify
;; all the properties for `:recipe'. These will inherit the rest of its recipe
;; from Doom or MELPA/ELPA/Emacsmirror:
;; (package! builtin-package :recipe (:nonrecursive t))
;; (package! builtin-package-2 :recipe (:repo "myfork/package"))
;; Specify a `:branch' to install a package from a particular branch or tag.
;; This is required for some packages whose default branch isn't 'master' (which
;; our package manager can't deal with; see radian-software/straight.el#279)
;; (package! builtin-package :recipe (:branch "develop"))
;; Use `:pin' to specify a particular commit to install.
;; (package! builtin-package :pin "1a2b3c4d5e")
;; Doom's packages are pinned to a specific commit and updated from release to
;; release. The `unpin!' macro allows you to unpin single packages...
;; (unpin! pinned-package)
;; ...or multiple packages
;; (unpin! pinned-package another-pinned-package)
;; ...Or *all* packages (NOT RECOMMENDED; will likely break things)
;; (unpin! t)
(package! copilot
:recipe (:host github :repo "copilot-emacs/copilot.el" :files ("*.el")))
(package! org-appear
:recipe (:type git :host github :repo "awth13/org-appear"))
(package! org-modern
:recipe (:type git :host github :repo "minad/org-modern"))

1426
phscroll.el Normal file

File diff suppressed because it is too large Load Diff