gists/gists.org

191 lines
6.4 KiB
Org Mode
Raw Normal View History

#+title: Gists by bram85
#+PROPERTY: header-args :mkdirp yes
#+begin_src org :tangle README.org
Gists referred from [[https://emacs.ch/@bram85][@bram85@emacs.ch]].
2022-11-24 07:52:25 +00:00
Unfortunately gitea has no gist support and there's no mature yet lightweight gist solution suitable for self-hosting, so resorting to this poor-man's setup of sharing gists with an audience.
#+end_src
2022-11-25 08:06:37 +00:00
* Termux keys :termux:emacs:
2022-11-23 16:18:43 +00:00
:PROPERTIES:
:URL: https://emacs.ch/@bram85/109393570150138285
:END:
Put this in ~/.termux/termux.properties for a better Emacs experience inside Termux.
#+begin_src conf :tangle gists/termux-emacs-keys.conf
extra-keys = [[ \
{key: ESC, popup: {macro: "CTRL g", display: "C-g"}}, \
{key: CTRL, popup: {macro: "CTRL x", display: "C-x"}}, \
{key: ALT, popup: {macro: "ALT x", display: "M-x"}}, \
{key: TAB}, \
{key: DEL, popup: {macro: "CTRL k", display: C-k}}, \
{key: LEFT, popup: HOME}, \
{key: DOWN, popup: PGDN}, \
{key: UP, popup: PGUP}, \
{key: RIGHT, popup: END} \
]]
#+end_src
2022-11-23 14:17:36 +00:00
2022-11-25 08:06:37 +00:00
* Nesting with use-package :emacs:usepackage:
2022-11-23 16:18:43 +00:00
:PROPERTIES:
:URL: https://emacs.ch/@bram85/109393551314878399
:END:
2022-11-23 14:17:36 +00:00
#+begin_src elisp :tangle gists/use-package-nesting.el
2022-11-24 07:52:40 +00:00
;; Demonstrate that use-package allows for nesting configurations,
;; although it is done semantically rather than syntactically. The
;; :after keyword makes sure that the 'bar' package is only evaluated
;; after the 'foo' package was loaded.
2022-11-23 14:17:36 +00:00
(use-package foo)
;; only loads after foo has been loaded
(use-package bar
:after foo)
#+end_src
2022-11-24 07:54:39 +00:00
2022-11-25 08:06:37 +00:00
* Track usage of Emacs packages over time :emacs:org:orgbabel:
2022-11-26 07:56:47 +00:00
:PROPERTIES:
:URL: https://emacs.ch/@bram85/109403483724552863
:END:
2022-11-25 08:06:37 +00:00
#+begin_src org :tangle gists/track-use-package-over-time.org
,* TODO Update Emacs package count
2022-11-26 06:58:45 +00:00
DEADLINE: <2022-12-26 Mon .+1m>
:PROPERTIES:
:LAST_REPEAT: [2022-11-26 Sat 07:57]
:END:
:LOGBOOK:
- State "DONE" from "TODO" [2022-11-26 Sat 07:57]
:END:
A small org file to keep track of some metric in a table, see [[https://orgmode.org/manual/Results-of-Evaluation.html][Results of Evaluation]] in the Org mode manual for more information.
In this case, count the number of packages in my Emacs init file. The code will automatically mark the task as DONE (thanks to [[https://emacs.ch/@leadore@toot.cafe/109406486013699362][@leadore@toot.cafe]]).
Press =C-c C-c= inside the code block to add a new entry to the table below.
,#+begin_src elisp :results table append
(save-excursion
(org-back-to-heading t)
(org-todo "DONE")
(with-temp-buffer
(insert-file-contents user-init-file)
(list (format-time-string "%F") (count-matches "(use-package "))))
,#+end_src
,#+RESULTS:
| 2022-11-25 | 140 |
2022-11-26 06:58:45 +00:00
| 2022-11-26 | 140 |
#+end_src
2022-11-26 07:09:02 +00:00
** Idea: event handlers :idea:
2022-11-26 07:56:47 +00:00
:PROPERTIES:
:URL: https://emacs.ch/@bram85/109408862071542059
:END:
2022-11-26 07:09:02 +00:00
Have =ON_<STATE>= properties containing code that evaluates when that state is reached. Can be looked up and evaluated from =org-after-todo-state-change-hook=.
#+begin_src org :tangle gists/org-event-handlers.org
,* TODO Update metric
:PROPERTIES:
:ON_DONE: (org-babel-execute-subtree)
:END:
,#+begin_src elisp :results table append
(with-temp-buffer
(insert-file-contents user-init-file)
(list (format-time-string "%F") (count-matches "(use-package ")))
,#+end_src
,#+RESULTS:
| 2022-11-26 | 140 |
#+end_src
2022-11-26 05:54:58 +00:00
* vertico-repeat setup :emacs:vertico:
2022-11-26 07:56:47 +00:00
:PROPERTIES:
:URL: https://emacs.ch/@bram85/109408577100294769
:END:
2022-11-26 05:54:58 +00:00
My vertico-repeat setup.
#+begin_src elisp :tangle gists/vertico-repeat.el
(use-package vertico-repeat
:straight (vertico-repeat :host github :repo "emacs-straight/vertico" :files ("extensions/vertico-repeat.el"))
:after (vertico savehist)
:bind
("M-g r" . vertico-repeat-select)
:config
(add-to-list 'savehist-additional-variables 'vertico-repeat-history)
:hook
(minibuffer-setup . vertico-repeat-save))
#+end_src
* Execute code on task state changes :emacs:org:
#+begin_src org :tangle gists/execute-code-on-task-state-change.org
The function below executes Lisp forms stored in properties of a TODO item, when it reaches a certain state. The function is supposed to be added to the =org-after-todo-state-change-hook=.
The property should be named =ON_<STATE>= where =STATE= is a state defined in =org-todo-keywords=. See also the example task below.
,#+begin_src elisp
(defun my/task-state-event-handler ()
"Called as part of org-after-todo-state-change-hook, which looks
for a property in the todo item at point and looks for properties
containing code that needs to be executed."
(if-let* ((state org-state)
(event-property-name (concat "ON_" state))
(properties (org-entry-properties))
(code-string (cdr (assoc event-property-name properties)))
(code (car (read-from-string code-string))))
(org-eval code)))
(add-hook 'org-after-todo-state-change-hook 'my/task-state-event-handler)
,#+end_src
,* TODO Example task
:PROPERTIES:
:ON_PROGRESS: (message "Busy!")
:ON_DONE: (message "Done!")
:END:
#+end_src
2022-11-26 07:51:28 +00:00
* Meta
** License
#+begin_src org :tangle LICENSE.txt
MIT License
Copyright (c) 2022 Bram Schoenmakers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#+end_src
** COMMENT Local variables
2022-11-24 07:54:39 +00:00
Auto tangle this file on save.
Local variables:
eval: (add-hook 'after-save-hook #'org-babel-tangle 0 t)
End: