changeset 605: | 3734c596d103 |
---|---|
parent 604: | 74a55d5decce |
child 606: | 6fc04c4d465c |
author: | Richard Westhaver <ellis@rwest.io> |
date: | Sun, 18 Aug 2024 01:52:22 -0400 |
files: | emacs/babel.org emacs/lib/inbox.el emacs/lib/publish.el |
description: | rm babel, update org config not sure how babel.org got back in the mix. most notable change is alphapapa's id-from-title stuff for html exports in publish.el. |
1.1--- a/emacs/babel.org Sat Aug 17 23:42:08 2024 -0400 1.2+++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3@@ -1,283 +0,0 @@ 1.4-#+title: babel 1.5-#+author: Richard Westhaver 1.6-#+description: Core Library of Babel 1.7-#+setupfile: https://cdn.compiler.company/org/clean.theme 1.8-#+property: header-args :exports both 1.9- 1.10-Welcome to the Core [[https://www.gnu.org/software/emacs/manual/html_node/org/Library-of-Babel.html][Library of Babel]]. This file contains a 1.11-collection of code blocks used throughout our Org documents. 1.12- 1.13-To load the library use ~C-c C-v i~ 1.14-* os 1.15-** systemd 1.16-#+name: systemd-list-units 1.17-#+begin_src sh :results replace 1.18-systemctl list-units --state=running | grep -v systemd | awk '{print $1}' | grep service 1.19-#+end_src 1.20- 1.21-* fs 1.22-** wc-dir-lines 1.23-#+name: wc-dir-lines 1.24-#+begin_src shell :var dir="." 1.25-cd $dir && cat * | wc -l 1.26-#+end_src 1.27- 1.28-** wc-dir-words 1.29-#+name: wc-dir-words 1.30-#+begin_src shell :var dir="." 1.31-cd $dir && cat * | wc -w 1.32-#+end_src 1.33- 1.34-** tokei-dir-lines 1.35-#+name: tokei-dir-lines 1.36-#+begin_src shell :var src=(org-sbe org-current-h1-title) :results output replace 1.37- cd ~/comp/$src 1.38- input=`tokei -C -o json` 1.39- echo $input | jq -r '.["Total"] | .code, .comments, .blanks' 1.40-#+end_src 1.41- 1.42-** tokei-dir-langs 1.43-#+name: tokei-dir-langs 1.44-#+begin_src shell :var src=(org-sbe org-current-h1-title) :results output replace 1.45- cd ~/comp/$src 1.46- input=`tokei -C -o json` 1.47- echo $input | jq -r '.["Total"].children | keys[]' 1.48-#+end_src 1.49- 1.50-** sum-str-nums 1.51-#+name: sum-str-nums 1.52-#+begin_src emacs-lisp :var s=tokei-dir-lines 1.53- (let ((tot 0)) 1.54- (cl-loop 1.55- with tot = 0 1.56- for i in (split-string s) do 1.57- (setf tot (+ tot (string-to-number i))) 1.58- finally return tot)) 1.59-#+end_src 1.60- 1.61-* org 1.62-** org-task-tbl 1.63-#+name: org-task-tbl 1.64-#+begin_src emacs-lisp 1.65- (let* ((ast (org-element-parse-buffer)) ;; built up the abstract syntax tree of the org buffer 1.66- item-types ; all occuring item types. It could be that some task has more item types than another. 1.67- tasks ; accumulation list for the tasks 1.68- current-task ; name of the current task (header of level 1) 1.69- task-items) ; items of the current task 1.70- (org-element-map ast 'headline 1.71- (lambda (hl) 1.72- (cl-case (org-element-property :level hl) 1.73- (1 ; We assume here that headers of level 1 are tasks. 1.74- (when current-task ; registering the old task 1.75- (setq tasks (cons (cons current-task (nreverse task-items)) tasks))) 1.76- (setq current-task (org-element-property :raw-value hl) ; preparing the new task 1.77- task-items nil)) 1.78- (2 ; item 1.79- (let ((item-type (org-element-property :raw-value hl))) 1.80- (setq item-types (cons item-type item-types)) 1.81- (setq task-items (cons (cons item-type (org-element-property :todo-keyword hl)) 1.82- task-items))))))) 1.83- (setq tasks (nreverse (cons (cons current-task (nreverse task-items)) tasks)) ;add the last task 1.84- item-types (sort (cl-remove-duplicates (nreverse item-types) :test 'string-equal) ; list of unique item types 1.85- #'string<)) ;;Sorting the items lexicographical. Other criteria could be applied. 1.86- ;;;;;;;;;; 1.87- ;; generating the output table: 1.88- (apply 1.89- #'list 1.90- (cons "Item" (mapcar #'car tasks)) ; header 1.91- 'hline 1.92- ;; rows: 1.93- (mapcar 1.94- ;; mapping the items to the todo states associated to the tasks: 1.95- (lambda (item-type) 1.96- (cons item-type 1.97- (mapcar 1.98- (lambda (task) 1.99- (let ((todo-status (cdr (assoc-string item-type task)))) 1.100- todo-status)) 1.101- tasks))) 1.102- item-types))) 1.103-#+end_src 1.104- 1.105-** org-headlines-map 1.106-#+name: org-headlines-map 1.107-#+begin_src elisp 1.108- (org-element-map (org-element-parse-buffer 'headline ) 1.109- 'headline 1.110- (lambda(hl) 1.111- (let ((parent (org-element-property :parent hl ))) 1.112- (and (eq (org-element-type parent) 'headline) 1.113- (list (org-element-property :title parent) (org-element-property :title hl)))))) 1.114- 1.115-#+end_src 1.116- 1.117-** make-info-tbl 1.118-#+name: make-info-tbl 1.119-#+header: :var version="0.1.0" 1.120-#+header: :var name=(org-sbe org-current-h1-title) 1.121-#+header: :var dir="/home/ellis/comp/" 1.122-#+begin_src emacs-lisp :results table replace 1.123- (let* ((src (concat dir name)) 1.124- (age (org-sbe "hg-log-age" ''(dir src))) 1.125- (rev (org-sbe "hg-rev" ''(dir src))) 1.126- (num (org-sbe "hg-id-num" ''(dir src))) 1.127- (cc1 (org-sbe "tokei-dir-lines" ''((dir src)))) 1.128- (cc2 (org-sbe "tokei-dir-langs" ''((dir src)))) 1.129- (nf (format "[[comp:/docs/%s][%s]]" name name)) 1.130- (rf (format "[[vc:comp/%s][%s:%s]]" name num rev)) 1.131- ;; (gf (format "[[https://github.com/richardwesthaver/%s][github]]" name)) 1.132- (vf (format "%s" rf)) 1.133- (lsum (org-sbe sum-str-nums ('s 'cc1))) 1.134- (l (split-string cc1)) 1.135- (lang (split-string cc2)) 1.136- (cf (format "%s = λ:%s #:%s _:%s" lsum (pop l) (pop l) (pop l)))) 1.137- `(hline 1.138- (name ,nf) 1.139- (version ,version) 1.140- (vc ,vf) 1.141- (updated ,age) 1.142- (lines ,cf) 1.143- (langs ,lang) 1.144- hline)) 1.145- #+end_src 1.146- 1.147- #+RESULTS: make-info-tbl 1.148- |---------+---------------------------| 1.149- | name | [[https://compiler.company//docs/org][org]] | 1.150- | version | 0.1.0 | 1.151- | vc | [[https://vc.compiler.company/comp/org][36+:4de12ceca1c7]] | 1.152- | updated | 4 days ago | 1.153- | lines | 10242 = λ:9409 #:44 _:789 | 1.154- | langs | (Html Org Svg) | 1.155- |---------+---------------------------| 1.156- 1.157-** make-includes 1.158-#+name: meta-make-includes 1.159-#+begin_src emacs-lisp :var i=() 1.160-`((includes ,i)) 1.161-#+end_src 1.162- 1.163-** make-files-tbl 1.164-#+name: ls-files 1.165-#+begin_src sh :results silent :var dir=(expand-file-name "~/comp") name=(org-sbe org-current-h1-title) 1.166- ls -lh $dir/$name --time-style=long-iso \ 1.167- |awk '{if (NR!=1) print $8, $5, $6"-"$7}' \ 1.168- |awk 'BEGIN{print "file size updated"}{print $0}' 1.169-#+end_src 1.170- 1.171-#+name: make-files-tbl 1.172-#+begin_src python :var tab=ls-files() :results table :colnames yes :hlines yes :exports results :eval no-export 1.173-return tab 1.174-#+end_src 1.175- 1.176-** org-current-h1-title 1.177-#+name: org-current-h1-title 1.178-#+begin_src emacs-lisp :results value 1.179- (org-element-property :title (save-excursion (org-up-heading-safe) (org-element-at-point))) 1.180-#+end_src 1.181- 1.182-#+RESULTS: org-current-h1-title 1.183-: org 1.184- 1.185-* emacs 1.186-** get-emacs-version 1.187-#+name: get-emacs-version 1.188-#+begin_src elisp :results output 1.189- (princ (concat (format "%s\n" (emacs-version)) 1.190- (format "Org v%s" (org-version)))) 1.191-#+end_src 1.192- 1.193-* vc 1.194-** hg-rev 1.195-#+name: hg-rev 1.196-#+begin_src sh :var src=(org-sbe org-current-h1-title) 1.197-cd ~/comp/$src && hg log -l 1 --template '{node|short}' 1.198-#+end_src 1.199- 1.200-#+RESULTS: hg-rev 1.201-: 4de12ceca1c7 1.202- 1.203-** hg-id-num 1.204-#+name: hg-id-num 1.205-#+begin_src shell :var src=(org-sbe org-current-h1-title) 1.206-cd ~/comp/$src && hg id -n 1.207-#+end_src 1.208- 1.209-#+RESULTS: hg-id-num 1.210-: 36+ 1.211- 1.212-** hg-log-age 1.213-#+name: hg-log-age 1.214-#+begin_src shell :var src=(org-sbe org-current-h1-title) 1.215- cd ~/comp/$src && hg log -l1 --template "{date|age}" 1.216-#+end_src 1.217- 1.218-#+RESULTS: hg-log-age 1.219-: 4 days ago 1.220- 1.221-* sh 1.222-** sh-ob-tangle 1.223-#+name: sh-ob-tangle 1.224-#+begin_src sh 1.225- emacs -Q --batch --eval " 1.226- (progn 1.227- (require 'ob-tangle) 1.228- (dolist (file command-line-args-left) 1.229- (with-current-buffer (find-file-noselect file) 1.230- (org-babel-tangle)))) 1.231- " "$@" 1.232-#+end_src 1.233- 1.234-* dot 1.235-** make-dot-tree 1.236-#+name: make-dot-tree 1.237-#+begin_src emacs-lisp :var table=org-headlines-map :results output 1.238- (mapcar #'(lambda (x) 1.239- (princ (format "\"%s\" -> \"%s\";\n" (cl-first x) (cl-second x)))) 1.240- table) 1.241-#+end_src 1.242- 1.243-** gen-dot-tree 1.244-#+name: gen-dot-tree 1.245-#+begin_src dot :file /tmp/tree.png :cmdline -Kdot -Tpng :var input=make-dot-tree 1.246-digraph { 1.247- rankdir=TB; 1.248- splines=true; 1.249- node [shape=box]; 1.250- $input 1.251- } 1.252-#+end_src 1.253- 1.254-* lisp 1.255-** user-slime 1.256-#+name: user-slime 1.257-#+begin_src emacs-lisp :results silent 1.258- (unless (slime-connected-p) (slime)) 1.259- (slime-eval '(ql:quickload :user)) 1.260-#+end_src 1.261-** std-slime 1.262-#+name: std-slime 1.263-#+begin_src emacs-lisp :results silent 1.264- (slime) 1.265- (slime-eval '(ql:quickload :std)) 1.266-#+end_src 1.267- 1.268-* rust 1.269-** cargo-update-dir 1.270-#+name: cargo-update-dir 1.271-#+begin_src sh :var dir=() 1.272-# update all crates in dir 1.273-set -eu 1.274-case $0 in 1.275- (/*) dir=${0%/*}/;; 1.276- (*/*) dir=./${0%/*};; 1.277- (*) dir=.;; 1.278-esac 1.279- 1.280-find "$dir/.." -name Cargo.toml -execdir cargo update \; 1.281-#+end_src 1.282-** rust-target-triple 1.283- #+name: rust-target-triple 1.284- #+begin_src shell 1.285- rustc -vV | sed -n -e 's/^host: //p' 1.286- #+end_src
2.1--- a/emacs/lib/inbox.el Sat Aug 17 23:42:08 2024 -0400 2.2+++ b/emacs/lib/inbox.el Sun Aug 18 01:52:22 2024 -0400 2.3@@ -53,6 +53,9 @@ 2.4 (defvar org-inbox-buffer-name "*Inbox*" 2.5 "The name of the org-inbox buffer.") 2.6 2.7+(defvar org-inbox-config-buffer-name "*Inbox Config*" 2.8+ "Then name of the org-inbox configuration buffer.") 2.9+ 2.10 (defvar org-inbox-properties 2.11 '("NEXT" "PREV" "FROM" "TO" "OWNER" "PROJECT" "BLOCKER")) 2.12 2.13@@ -210,6 +213,7 @@ 2.14 ((> (cdr a) (cdr b)) nil) 2.15 ;; nil ommitted since cond defaults to it 2.16 )))) 2.17+ 2.18 (defun org-inbox-sort () 2.19 "Sort the current heading by todo order followed by priority." 2.20 (interactive) 2.21@@ -229,5 +233,38 @@ 2.22 (when-let ((inbox (get-buffer org-inbox-buffer-name))) 2.23 (kill-buffer inbox))) 2.24 2.25+;;; dblocks 2.26+(defun org-dblock-write:summary ()) 2.27+ 2.28+(defun org-inbox-show-config (&optional buffer position parameters) 2.29+ (interactive) 2.30+ (switch-to-buffer org-inbox-config-buffer-name) 2.31+ (erase-buffer) 2.32+ (remove-overlays) 2.33+ (widget-insert "\n\n") 2.34+ (widget-create 'push-button 2.35+ :notify (lambda(_widget &rest _ignore) 2.36+ (with-current-buffer buffer 2.37+ (goto-char position) 2.38+ ) 2.39+ (kill-buffer) 2.40+ (org-ctrl-c-ctrl-c)) 2.41+ (propertize "Apply" 'face 'font-lock-comment-face)) 2.42+ (widget-insert " ") 2.43+ (widget-create 'push-button 2.44+ :notify (lambda (_widget &rest _ignore) 2.45+ (kill-buffer)) 2.46+ (propertize "Cancel" 'face 'font-lock-string-face)) 2.47+ (use-local-map widget-keymap) 2.48+ (widget-setup)) 2.49+ 2.50+(defun org-inbox-configure-dblock () 2.51+ "Configure the current org-inbox-dblock at point." 2.52+ (interactive) 2.53+ (with-demoted-errors "Error: %S" 2.54+ (let* ((beginning (org-beginning-of-dblock)) 2.55+ (parameters (org-prepare-dblock))) 2.56+ (org-inbox-show-config-buffer (current-buffer) beginning parameters)))) 2.57+ 2.58 (provide 'inbox) 2.59 ;; inbox.el ends here
3.1--- a/emacs/lib/publish.el Sat Aug 17 23:42:08 2024 -0400 3.2+++ b/emacs/lib/publish.el Sun Aug 18 01:52:22 2024 -0400 3.3@@ -107,6 +107,85 @@ 3.4 :html-preamble ,html-nav 3.5 :html-postamble ,html-foot))) 3.6 3.7+ (defun org-export-get-reference-title (datum info) 3.8+ "Like `org-export-get-reference', except uses heading titles instead of random numbers." 3.9+ (let ((cache (plist-get info :internal-references))) 3.10+ (or (car (rassq datum cache)) 3.11+ (let* ((crossrefs (plist-get info :crossrefs)) 3.12+ (cells (org-export-search-cells datum)) 3.13+ ;; Preserve any pre-existing association between 3.14+ ;; a search cell and a reference, i.e., when some 3.15+ ;; previously published document referenced a location 3.16+ ;; within current file (see 3.17+ ;; `org-publish-resolve-external-link'). 3.18+ ;; 3.19+ ;; However, there is no guarantee that search cells are 3.20+ ;; unique, e.g., there might be duplicate custom ID or 3.21+ ;; two headings with the same title in the file. 3.22+ ;; 3.23+ ;; As a consequence, before re-using any reference to 3.24+ ;; an element or object, we check that it doesn't refer 3.25+ ;; to a previous element or object. 3.26+ (new (or (cl-some 3.27+ (lambda (cell) 3.28+ (let ((stored (cdr (assoc cell crossrefs)))) 3.29+ (when stored 3.30+ (let ((old (org-export-format-reference stored))) 3.31+ (and (not (assoc old cache)) stored))))) 3.32+ cells) 3.33+ (when (org-element-property :raw-value datum) 3.34+ ;; Heading with a title 3.35+ (org-export-new-title-reference datum cache)) 3.36+ ;; NOTE: This probably breaks some Org Export 3.37+ ;; feature, but if it does what I need, fine. 3.38+ (org-export-format-reference 3.39+ (org-export-new-reference cache)))) 3.40+ (reference-string new)) 3.41+ ;; Cache contains both data already associated to 3.42+ ;; a reference and in-use internal references, so as to make 3.43+ ;; unique references. 3.44+ (dolist (cell cells) (push (cons cell new) cache)) 3.45+ ;; Retain a direct association between reference string and 3.46+ ;; DATUM since (1) not every object or element can be given 3.47+ ;; a search cell (2) it permits quick lookup. 3.48+ (push (cons reference-string datum) cache) 3.49+ (plist-put info :internal-references cache) 3.50+ reference-string)))) 3.51+ 3.52+ (defun org-export-new-title-reference (datum cache) 3.53+ "Return new reference for DATUM that is unique in CACHE." 3.54+ (cl-macrolet ((inc-suffixf (place) 3.55+ `(progn 3.56+ (string-match (rx bos 3.57+ (minimal-match (group (1+ anything))) 3.58+ (optional "--" (group (1+ digit))) 3.59+ eos) 3.60+ ,place) 3.61+ ;; HACK: `s1' instead of a gensym. 3.62+ (-let* (((s1 suffix) (list (match-string 1 ,place) 3.63+ (match-string 2 ,place))) 3.64+ (suffix (if suffix 3.65+ (string-to-number suffix) 3.66+ 0))) 3.67+ (setf ,place (format "%s--%s" s1 (cl-incf suffix))))))) 3.68+ (let* ((title (org-element-property :raw-value datum)) 3.69+ (ref (url-hexify-string (substring-no-properties title))) 3.70+ (parent (org-element-property :parent datum))) 3.71+ (while (--any (equal ref (car it)) 3.72+ cache) 3.73+ ;; Title not unique: make it so. 3.74+ (if parent 3.75+ ;; Append ancestor title. 3.76+ (setf title (concat (org-element-property :raw-value parent) 3.77+ "--" title) 3.78+ ref (url-hexify-string (substring-no-properties title)) 3.79+ parent (org-element-property :parent parent)) 3.80+ ;; No more ancestors: add and increment a number. 3.81+ (inc-suffixf ref))) 3.82+ ref))) 3.83+ 3.84+(advice-add #'org-export-get-reference :override #'org-export-get-reference-title) 3.85+ 3.86 ;;;###autoload 3.87 (defun publish (&optional sitemap static force async) 3.88 "publish `rwest-io' content.