Browse Source

custom internal functions prefix my--.., interactive my/..

master
Marc 1 year ago
parent
commit
844d2100e2
1 changed files with 31 additions and 32 deletions
  1. 63
      config.org

63
config.org

@ -38,15 +38,14 @@ Emacs variables are dynamically scoped. That's unusual for most languages, so di
These functions updates config.el whenever changes in config.org are made. The update will be active after saving. These functions updates config.el whenever changes in config.org are made. The update will be active after saving.
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun me/tangle-config ()
"Export code blocks from the literate config file
asynchronously."
(defun my/tangle-config ()
"Export code blocks from the literate config file."
(interactive) (interactive)
;; prevent emacs from killing until tangle-process finished ;; prevent emacs from killing until tangle-process finished
(add-to-list 'kill-emacs-query-functions (add-to-list 'kill-emacs-query-functions
(lambda () (lambda ()
(or (not (process-live-p (get-process "tangle-process"))) (or (not (process-live-p (get-process "tangle-process")))
(y-or-n-p "\"me/tangle-config\" is running; kill it? "))))
(y-or-n-p "\"my/tangle-config\" is running; kill it? "))))
(org-babel-tangle-file config-org config-el) (org-babel-tangle-file config-org config-el)
(message "reloading user-init-file") (message "reloading user-init-file")
(load-file config-el)) (load-file config-el))
@ -54,13 +53,13 @@ asynchronously."
(add-hook 'org-mode-hook (add-hook 'org-mode-hook
(lambda () (lambda ()
(if (equal (buffer-file-name) config-org) (if (equal (buffer-file-name) config-org)
(me/add-local-hook 'after-save-hook 'me/tangle-config))))
(my--add-local-hook 'after-save-hook 'my/tangle-config))))
(defun me/add-local-hook (hook function)
(defun my--add-local-hook (hook function)
"Add buffer-local hook." "Add buffer-local hook."
(add-hook hook function :local t)) (add-hook hook function :local t))
(defun me/async-process (command &optional name filter)
(defun my/async-process (command &optional name filter)
"Start an async process by running the COMMAND string with bash. Return the "Start an async process by running the COMMAND string with bash. Return the
process object for it. process object for it.
@ -148,15 +147,15 @@ Restore it to reasonable value after init. Also stop garbage collection during m
(defconst 30mb 31457280) (defconst 30mb 31457280)
(defconst 50mb 52428800) (defconst 50mb 52428800)
(defun me/defer-garbage-collection ()
(defun my--defer-garbage-collection ()
(setq gc-cons-threshold most-positive-fixnum)) (setq gc-cons-threshold most-positive-fixnum))
(defun me/restore-garbage-collection ()
(defun my--restore-garbage-collection ()
(run-at-time 1 nil (lambda () (setq gc-cons-threshold 30mb)))) (run-at-time 1 nil (lambda () (setq gc-cons-threshold 30mb))))
(add-hook 'emacs-startup-hook 'me/restore-garbage-collection 100)
(add-hook 'minibuffer-setup-hook 'me/defer-garbage-collection)
(add-hook 'minibuffer-exit-hook 'me/restore-garbage-collection)
(add-hook 'emacs-startup-hook 'my--restore-garbage-collection 100)
(add-hook 'minibuffer-setup-hook 'my--defer-garbage-collection)
(add-hook 'minibuffer-exit-hook 'my--restore-garbage-collection)
(setq read-process-output-max 1mb) ;; lsp-mode's performance suggest (setq read-process-output-max 1mb) ;; lsp-mode's performance suggest
#+end_src #+end_src
@ -302,7 +301,7 @@ Restore it to reasonable value after init. Also stop garbage collection during m
** Themes ** Themes
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun me/toggle-theme ()
(defun my/toggle-theme ()
(interactive) (interactive)
(when (or *sys/windows* *sys/linux*) (when (or *sys/windows* *sys/linux*)
(if (eq (car custom-enabled-themes) 'tango-dark) (if (eq (car custom-enabled-themes) 'tango-dark)
@ -312,7 +311,7 @@ Restore it to reasonable value after init. Also stop garbage collection during m
(disable-theme 'tango) (disable-theme 'tango)
(load-theme 'tango-dark))))) (load-theme 'tango-dark)))))
(bind-key "C-c t" 'me/toggle-theme)
(bind-key "C-c t" 'my/toggle-theme)
#+END_SRC #+END_SRC
Windows Theme: Windows Theme:
@ -708,17 +707,17 @@ end_src
("<escape>" . company-abort)) ("<escape>" . company-abort))
:hook :hook
(after-init . global-company-mode) (after-init . global-company-mode)
(emacs-lisp-mode . me/company-elisp)
(org-mode . me/company-org)
(emacs-lisp-mode . my--company-elisp)
(org-mode . my--company-org)
:config :config
(defun me/company-elisp ()
(defun my--company-elisp ()
(message "set up company for elisp") (message "set up company for elisp")
(set (make-local-variable 'company-backends) (set (make-local-variable 'company-backends)
'(company-capf ;; capf needs to be before yasnippet, or lsp fucks up completion for elisp '(company-capf ;; capf needs to be before yasnippet, or lsp fucks up completion for elisp
company-yasnippet company-yasnippet
company-dabbrev-code company-dabbrev-code
company-files))) company-files)))
(defun me/company-org ()
(defun my--company-org ()
(set (make-local-variable 'company-backends) (set (make-local-variable 'company-backends)
'(company-capf company-files)) '(company-capf company-files))
;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t) ;; (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
@ -778,7 +777,7 @@ When moving BAR to archive, it will go to FILENAME.org_archive below the heading
[[http://doc.endlessparentheses.com/Var/org-archive-location.html][Other examples]] [[http://doc.endlessparentheses.com/Var/org-archive-location.html][Other examples]]
** org ** org
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun me--buffer-prop-set (name value)
(defun my--buffer-prop-set (name value)
"Set a file property called NAME to VALUE in buffer file. "Set a file property called NAME to VALUE in buffer file.
If the property is already set, replace its value." If the property is already set, replace its value."
(setq name (downcase name)) (setq name (downcase name))
@ -797,7 +796,7 @@ If the property is already set, replace its value."
(beginning-of-line))) (beginning-of-line)))
(insert "#+" name ": " value "\n"))))) (insert "#+" name ": " value "\n")))))
(defun me--buffer-prop-remove (name)
(defun my--buffer-prop-remove (name)
"Remove a buffer property called NAME." "Remove a buffer property called NAME."
(org-with-point-at 1 (org-with-point-at 1
(when (re-search-forward (concat "\\(^#\\+" name ":.*\n?\\)") (when (re-search-forward (concat "\\(^#\\+" name ":.*\n?\\)")
@ -821,7 +820,7 @@ If the property is already set, replace its value."
("S-<left>" . org-shiftleft)) ("S-<left>" . org-shiftleft))
:config :config
(defun me/org-company ()
(defun my--org-company ()
(set (make-local-variable 'company-backends) (set (make-local-variable 'company-backends)
'(company-capf company-files)) '(company-capf company-files))
(add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t) (add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
@ -992,7 +991,7 @@ Sort agenda by deadline and priority
Customize the org agenda Customize the org agenda
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(defun me--org-skip-subtree-if-priority (priority)
(defun my--org-skip-subtree-if-priority (priority)
"Skip an agenda subtree if it has a priority of PRIORITY. "Skip an agenda subtree if it has a priority of PRIORITY.
PRIORITY may be one of the characters ?A, ?B, or ?C." PRIORITY may be one of the characters ?A, ?B, or ?C."
@ -1013,7 +1012,7 @@ Customize the org agenda
(org-agenda-start-on-weekday nil) (org-agenda-start-on-weekday nil)
(org-agenda-overriding-header "Nächste 7 Tage:"))) (org-agenda-overriding-header "Nächste 7 Tage:")))
(alltodo "" (alltodo ""
((org-agenda-skip-function '(or (me--org-skip-subtree-if-priority ?A)
((org-agenda-skip-function '(or (my--org-skip-subtree-if-priority ?A)
(org-agenda-skip-if nil '(scheduled deadline)))) (org-agenda-skip-if nil '(scheduled deadline))))
(org-agenda-overriding-header "Sonstige Aufgaben:"))))))) (org-agenda-overriding-header "Sonstige Aufgaben:")))))))
#+END_SRC #+END_SRC
@ -1068,33 +1067,33 @@ org-roam-db-sync
:init :init
(setq org-roam-v2-ack t) (setq org-roam-v2-ack t)
(defun me--buffer-roam-note-p ()
(defun my--buffer-roam-note-p ()
"Return non-nil if the currently visited buffer is a note." "Return non-nil if the currently visited buffer is a note."
(and buffer-file-name (and buffer-file-name
(string-prefix-p (string-prefix-p
(expand-file-name (file-name-as-directory MY--PATH_ORG_ROAM)) (expand-file-name (file-name-as-directory MY--PATH_ORG_ROAM))
(file-name-directory buffer-file-name)))) (file-name-directory buffer-file-name))))
(defun me/org-roam-filter-by-tag (tag-name)
(defun my--org-roam-filter-by-tag (tag-name)
(lambda (node) (lambda (node)
(member tag-name (org-roam-node-tags node)))) (member tag-name (org-roam-node-tags node))))
(defun me/org-roam-list-notes-by-tag (tag-name)
(defun my--org-roam-list-notes-by-tag (tag-name)
(mapcar #'org-roam-node-file (mapcar #'org-roam-node-file
(seq-filter (seq-filter
(me/org-roam-filter-by-tag tag-name)
(my--org-roam-filter-by-tag tag-name)
(org-roam-node-list)))) (org-roam-node-list))))
(defun me/org-roam-refresh-agenda-list ()
(defun my/org-roam-refresh-agenda-list ()
"Add all org roam files with #+filetags: Project" "Add all org roam files with #+filetags: Project"
(interactive) (interactive)
(nconc org-agenda-files (nconc org-agenda-files
(me/org-roam-list-notes-by-tag "Project")))
(my--org-roam-list-notes-by-tag "Project")))
:config :config
(require 'org-roam-dailies) ;; ensure the keymap is available (require 'org-roam-dailies) ;; ensure the keymap is available
(org-roam-db-autosync-mode) (org-roam-db-autosync-mode)
;; build the agenda list the first ime for the session ;; build the agenda list the first ime for the session
(me/org-roam-refresh-agenda-list)
(my/org-roam-refresh-agenda-list)
:custom :custom
(org-roam-directory MY--PATH_ORG_ROAM) (org-roam-directory MY--PATH_ORG_ROAM)
@ -1583,11 +1582,11 @@ deactivate
:mode :mode
("\\.beancount$" . beancount-mode) ("\\.beancount$" . beancount-mode)
:hook :hook
(beancount-mode . me/beancount-company)
(beancount-mode . my--beancount-company)
:init :init
(add-hook 'beancount-mode-hook 'company/beancount-mode-hook) (add-hook 'beancount-mode-hook 'company/beancount-mode-hook)
:config :config
(defun me/beancount-company ()
(defun my--beancount-company ()
(set (make-local-variable 'company-backends) (set (make-local-variable 'company-backends)
'(company-beancount))) '(company-beancount)))
(setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount")) (setq beancount-filename-main "/home/marc/Archiv/Finanzen/Transaktionen/transactions.beancount"))

Loading…
Cancel
Save