From 37897c48727ea07207dc735b4664e0c0d9913167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tr=C3=A9meur?= Date: Mon, 12 Dec 2022 19:12:15 +0000 Subject: [PATCH] Org-format and agenda improvements --- .gitignore | 1 + agenda.el | 7 +- config.org | 150 +++++++++++++++++++++++++++---------------- custom/org-format.el | 12 ++++ custom/workday.el | 12 ++++ 5 files changed, 127 insertions(+), 55 deletions(-) create mode 100644 custom/workday.el diff --git a/.gitignore b/.gitignore index 66ad30d..1fcd461 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ nohup.out \#* network-security.data nov-places +places request/* tramp transient/* diff --git a/agenda.el b/agenda.el index e7c2649..3cf63b3 100644 --- a/agenda.el +++ b/agenda.el @@ -1,4 +1,9 @@ -(setq org-agenda-files '("~/Documents/drive/org/calendar")) +(load-file "~/.emacs.d/custom/workday.el") +(if (isworkday) + (if (< (string-to-number (format-time-string "%H")) 18) + (if (> (string-to-number (format-time-string "%H")) 7) + (setq org-agenda-files (list "~/Documents/drive/org/calendar/admin.org" "~/Documents/drive/org/calendar/home.org" "~/Documents/drive/org/calendar/music.org" "~/Documents/drive/org/calendar/work.org"))) + (setq org-agenda-files (list "~/Documents/drive/org/calendar/admin.org" "~/Documents/drive/org/calendar/home.org" "~/Documents/drive/org/calendar/music.org" "~/Documents/drive/org/calendar/personal.org")))) (setq org-agenda-prefix-format '((agenda . "%?-12t%s"))) (setq org-deadline-warning-days 0) (load-file "~/.emacs.d/agenda-common.el") diff --git a/config.org b/config.org index 19c6a09..8c1460f 100644 --- a/config.org +++ b/config.org @@ -17,23 +17,19 @@ Define functions that specify what OS I’m on, also whether I’m at work or no #+BEGIN_SRC emacs-lisp (defun islin () "Return true if on linux" - (string-equal system-type "gnu/linux") - ) + (string-equal system-type "gnu/linux")) (defun iswin () "Return true if on windows" - (string-equal system-type "windows-nt") - ) + (string-equal system-type "windows-nt")) (defun ismac () "Return true if on macos" - (string-equal system-type "darwin") - ) + (string-equal system-type "darwin")) (defun atwork () "Return true if at work" - (string-equal user-login-name "3055822") - ) + (string-equal user-login-name "3055822")) #+END_SRC * It's not 1986 @@ -65,30 +61,19 @@ Also suppress certain warnings that would otherwise come up all the time and con (setq byte-compile-warnings '(cl-functions)) #+END_SRC -* =use-package= +* Miscellaneous changes to make to the basic config -Set up package handling, including =use-package=. Some of the =org= tools I use are from Non-GNU ELPA, I think. Most of this is the standard =use-package= setup stuff. +Firstly, tell Emacs where to look for custom functions. #+BEGIN_SRC emacs-lisp - (package-initialize) - - (add-to-list 'package-archives - '("melpa" . "https://melpa.org/packages/") t) - (add-to-list 'package-archives '("nongnu" . "https://elpa.nongnu.org/nongnu/")) - - (setq package-check-signature nil) - - (unless (package-installed-p 'use-package) - (package-refresh-contents) - (package-install 'use-package)) - - (require 'use-package-ensure) - (setq use-package-always-ensure t) + (defun load-directory (dir) + (let ((load-it (lambda (f) + (load-file (concat (file-name-as-directory dir) f))))) + (mapc load-it (directory-files dir nil "\\.el$")))) + (load-directory "~/.emacs.d/custom/") #+END_SRC -* Miscellaneous changes to make to the basic config - -Firstly, I don’t want finding files to be case-sensitive, same as in =zsh=: +I don’t want finding files to be case-sensitive, same as in =zsh=: #+BEGIN_SRC emacs-lisp (setq completion-ignore-case t) @@ -104,6 +89,14 @@ Make the +window+ /frame/ look nice and clean. Scroll bars behave pointlessly on (scroll-bar-mode -1) #+END_SRC +Make everything just a little tiny bit transparent unless I’m using the boring Windows desktop. + +#+BEGIN_SRC emacs-lisp + (unless (atwork) + (set-frame-parameter (selected-frame) 'alpha 95) + (add-to-list 'default-frame-alist '(alpha . 95))) +#+END_SRC + Stop creating all those =~= files everywhere. Put them somewhere that I can ignore them. #+BEGIN_SRC emacs-lisp @@ -117,6 +110,21 @@ This gives buffers sensible names. (setq uniquify-buffer-name-style 'forward) #+END_SRC +Give me an excuse to use regex more often (from [[https://git.sr.ht/~technomancy/better-defaults][Better Defaults]]). + +#+BEGIN_SRC emacs-lisp + (global-set-key (kbd "C-s") 'isearch-forward-regexp) + (global-set-key (kbd "C-r") 'isearch-backward-regexp) + (global-set-key (kbd "C-M-s") 'isearch-forward) + (global-set-key (kbd "C-M-r") 'isearch-backward) +#+END_SRC + +Go back to the same place in a file. + +#+BEGIN_SRC emacs-lisp + (save-place-mode 1) +#+END_SRC + Turn on automatic bracket/quotation mark matching. #+BEGIN_SRC emacs-lisp @@ -179,6 +187,27 @@ Windows likes to set the default directory to the folder where the Emacs binary (setq default-directory "~/")) #+END_SRC +* =use-package= + +Set up package handling, including =use-package=. Some of the =org= tools I use are from Non-GNU ELPA, I think. Most of this is the standard =use-package= setup stuff. + +#+BEGIN_SRC emacs-lisp + (package-initialize) + + (add-to-list 'package-archives + '("melpa" . "https://melpa.org/packages/") t) + (add-to-list 'package-archives '("nongnu" . "https://elpa.nongnu.org/nongnu/")) + + (setq package-check-signature nil) + + (unless (package-installed-p 'use-package) + (package-refresh-contents) + (package-install 'use-package)) + + (require 'use-package-ensure) + (setq use-package-always-ensure t) +#+END_SRC + * Packages, modes, etc. ** =bibtex= @@ -454,6 +483,16 @@ Settings for export, fairly basic because the only thing I regularly export is H (setq org-html-head "") #+END_SRC +Export non-breaking spaces properly; from, believe it or not, [[https://orgmode.org/manual/Advanced-Export-Configuration.html][the Org Manual]]. + +#+BEGIN_SRC emacs-lisp + (defun my-html-filter-nobreaks (text backend info) + (when (org-export-derived-backend-p backend 'html) + (replace-regexp-in-string " " " " text))) + (add-to-list 'org-export-filter-plain-text-functions + 'my-html-filter-nobreaks) +#+END_SRC + *** Packages **** =org-agenda-property= @@ -485,20 +524,22 @@ Automate a tiny part of something I was previously doing manually. **** =org-modern= and =org-bullets= -Use =org-modern= on =emacs27= and above (although I’m still not wild about it), =org-bullets= otherwise. +Use =org-modern= on =emacs27= and above (although I’m still not wild about it), =org-bullets= otherwise. [[https://github.com/minad/org-modern/issues/5#issuecomment-1318003940][Fix for issue with table widths]], which makes me slightly less not-wild. #+BEGIN_SRC emacs-lisp - (unless (version< emacs-version "27") - (use-package org-modern - :hook - (org-mode . org-modern-mode))) + (unless (version< emacs-version "27") + (use-package org-modern + :hook + (org-mode . org-modern-mode)) + (set-face-attribute 'org-table nil :inherit 'fixed-pitch) + (custom-set-variables '(org-modern-table nil))) - (if (version< emacs-version "27") - (use-package org-bullets - :custom - (org-bullets-bullet-list '("✸")) - (org-ellipsis " ⤵") - :hook (org-mode . org-bullets-mode))) + (if (version< emacs-version "27") + (use-package org-bullets + :custom + (org-bullets-bullet-list '("✸")) + (org-ellipsis " ⤵") + :hook (org-mode . org-bullets-mode))) #+END_SRC **** =org-noter= @@ -546,12 +587,23 @@ Set the keybinding, set the week to start on Monday because I’m not the Univer Set the files to be included. #+BEGIN_SRC emacs-lisp - (unless (atwork) - (setq org-agenda-files (list "~/Documents/drive/org/calendar" - "~/Documents/drive/org/habit.org"))) - (when (atwork) - (setq org-agenda-files (list "~/Documents/drive/org/calendar" - "~/Documents/drive/org/acwri.org"))) + (add-to-list 'org-agenda-files "~/Documents/drive/org/calendar/music.org") + (add-to-list 'org-agenda-files "~/Documents/drive/org/calendar/admin.org") + (if (atwork) + (progn + (add-to-list 'org-agenda-files "~/Documents/drive/org/calendar/work.org") + (add-to-list 'org-agenda-files "~/Documents/drive/org/calendar/acwri.org")) + (progn + (add-to-list 'org-agenda-files "~/Documents/drive/org/calendar/home.org") + (if (isworkday) + (if (< (string-to-number (format-time-string "%H")) 18) + (if (> (string-to-number (format-time-string "%H")) 7) + (progn + (add-to-list 'org-agenda-files "~/Documents/drive/org/calendar/work.org") + (add-to-list 'org-agenda-files "~/Documents/drive/org/calendar/acwri.org"))) + (progn + (add-to-list 'org-agenda-files "~/Documents/drive/org/calendar/personal.org") + (add-to-list 'org-agenda-files "~/Documents/drive/org/calendar/habit.org")))))) #+END_SRC Set how the agenda looks. @@ -779,16 +831,6 @@ Use the =mixed-pitch= package to determine the font intelligently in modes that * Startup -Firstly, tell Emacs where to look for custom functions. - -#+BEGIN_SRC emacs-lisp - (defun load-directory (dir) - (let ((load-it (lambda (f) - (load-file (concat (file-name-as-directory dir) f))))) - (mapc load-it (directory-files dir nil "\\.el$")))) - (load-directory "~/.emacs.d/custom/") -#+END_SRC - Set the =*scratch*= buffer to =org-mode=. #+BEGIN_SRC emacs-lisp diff --git a/custom/org-format.el b/custom/org-format.el index 52885ee..5f71c4d 100644 --- a/custom/org-format.el +++ b/custom/org-format.el @@ -4,9 +4,21 @@ (while (re-search-forward " -" nil t) (replace-match " –")) (goto-char (region-beginning)) + (while (re-search-forward " –" nil t) + (replace-match " –")) + (goto-char (region-beginning)) + (while (re-search-forward " \\.\\.\\." nil t) + (replace-match " …")) + (goto-char (region-beginning)) + (while (re-search-forward " …" nil t) + (replace-match " …")) + (goto-char (region-beginning)) (while (re-search-forward "'" nil t) (replace-match "’")) (goto-char (region-beginning)) + (while (re-search-forward " \n" nil t) + (replace-match "\n")) + (goto-char (region-beginning)) (while (re-search-forward "\n\"" nil t) (replace-match "\n“")) (goto-char (region-beginning)) diff --git a/custom/workday.el b/custom/workday.el new file mode 100644 index 0000000..28a6850 --- /dev/null +++ b/custom/workday.el @@ -0,0 +1,12 @@ +(setq daysoff '("2022-12-23" "2022-12-24" "2022-12-25" "2022-12-26" "2022-12-27" "2022-12-28" "2022-12-29" "2022-12-30" "2022-12-31" "2023-01-01" "2023-01-02" "2023-01-03" "2023-03-17" "2023-04-07" "2023-04-14" "2023-05-01" "2023-07-12" "2023-07-13" "2023-12-22" "2023-12-23" "2023-12-24" "2023-12-25" "2023-12-26" "2023-12-27" "2023-12-28" "2023-12-29" "2023-12-30" "2023-12-31" "2023-01-01" "2023-01-02" "2024-03-18" "2024-03-29" "2024-03-30" "2024-03-31" "2024-04-01" "2024-04-02" "2024-04-03" "2024-04-04" "2024-04-05" "2024-05-06" "2024-07-12" "2024-07-15" "2024-12-23" "2024-12-24" "2024-12-25" "2024-12-26" "2024-12-27" "2024-12-28" "2024-12-29" "2024-12-30" "2024-12-31" "2025-01-01")) ;; to update in 2025 +(if (equal (format-time-string "%a") "Sat") + (setq workday nil) + (if (equal (format-time-string "%a") "Sun") + (setq workday nil) + (if (member (format-time-string "%Y-%m-%d") daysoff) + (setq workday nil) + (setq workday t)))) + +(defun isworkday () + (eq workday t)) +