mken.paste.lol / library.org · 1 year ago·
-
Utility functions
+begin_src scheme
;; Emacs Lisp like defvar (define documentation-table (make-hashtable equal-hash equal?)) (define-macro (defvar name initial-value docstring)
(begin (define ,name ,initial-value) (hashtable-set! documentation-table ',name ,docstring))) ;; Emacs Lisp like defun (define interactive-table (make-hashtable equal-hash equal?)) (define-macro (defun name args docstring interactive body)
(begin (define ,name (lambda ,args ,body)) (hashtable-set! documentation-table ',name ,docstring) (hashtable-set! interactive-table ',name ,interactive))) (define (documentation name) (hashtable-ref documentation-table name "No documentation available."));; Some other useful Emacs Lisp like functions (define (1+ value) (+ 1 value)) (define (1- value) (- value 1))
;; Redefine some functions which don't make sense on iOS (define (sleep timeout) "Sleep is not supported in beorg.") (define (timer proc sec) "Timers are not supported in beorg.")
;; Keyboard shortcuts (define key-table (make-hashtable equal-hash equal?)) (define (define-key scope shortcut command) (let ((current-shortcuts (hashtable-ref key-table scope '()))) (hashtable-set! key-table scope (append (list (list shortcut command)) current-shortcuts)))) (define (keys-in-scope scope) (hashtable-ref key-table scope '())) (define command-title-table (make-hashtable equal-hash equal?)) (define (define-command-title command title) (hashtable-set! command-title-table command title)) (define (title-for-command command) (hashtable-ref command-title-table command #f))
(define (grep pattern text) (let ((pattern-lowercase (string-downcase pattern))) (string-join (filter (lambda (x) (string-contains? (string-downcase x) pattern-lowercase)) (string-split text "\n")) "\n")))
+end_src
-
Items An item (task) is represented by an association list. Here are some helper functions to extract values.
+begin_src scheme
(defvar current-item #f "The current item being edited. If no item is being edited then #f") (define (item-file item) (cadr (assoc 'file item))) (define (item-headline item) (cadr (assoc 'headline item))) (define (item-state item) (cadr (assoc 'state item))) (define (item-priority item) (cadr (assoc 'priority item))) (define (item-scheduled item) (cadr (assoc 'scheduled item))) (define (item-deadline item) (cadr (assoc 'deadline item))) (define (item-active-date item) (cadr (assoc 'active-date item))) (define (item-overdue item) (cadr (assoc 'overdue item))) (define (item-tags item) (cadr (assoc 'tags item))) (define (item-inherited-tags item) (cadr (assoc 'inherited-tags item))) (define (item-all-tags item) (append (item-tags item) (item-inherited-tags item))) ;; If an item doesn't have a properties drawer then it will be an empty list (define (item-properties item) (cadr (assoc 'properties item))) ;; Return the value of property from item's property drawer or an empty string is it doesn't exist (define (item-property item property) (let ((pair (assoc property (cadr (assoc 'properties item))))) (if pair (cadr pair) ""))) ;; If item is a calendar event then item-is-file will return #f (define (item-is-file item) (not (string=? (item-file item) ""))) (define (set-current-item-headline! headline) (native-current-item-set "headline" headline)) (define (set-current-item-state! state) (native-current-item-set "state" state)) (define (set-current-item-priority! priority) (native-current-item-set "priority" priority)) (define (set-current-item-scheduled! scheduled) (native-current-item-set "scheduled" scheduled)) (define (set-current-item-deadline! deadline) (native-current-item-set "deadline" deadline)) (define (set-current-item-active-date! active-date) (native-current-item-set "active-date" show-on)) (define (set-current-item-scheduled-with-time! scheduled) (native-current-item-set "scheduled-with-time" scheduled)) (define (set-current-item-deadline-with-time! deadline) (native-current-item-set "deadline-with-time" deadline)) (define (set-current-item-active-date-with-time! active-date) (native-current-item-set "active-date-with-time" show-on)) (define (delete-current-item-scheduled!) (native-current-item-set "scheduled" #f)) (define (delete-current-item-deadline!) (native-current-item-set "deadline" #f)) (define (delete-current-item-active-date!) (native-current-item-set "active-date" #f)) (define (set-current-item-tags! tags) (native-current-item-set "tags" (string-join tags ":"))) (define (set-current-item-property! property value) (native-current-item-set "property" (string-append property ":" value))) ;; Convenience functions to get effort from an item (define (effort->minutes effort) (let ((components (string-split effort ":")) (hours ( 60 (string->number (car components)))) (minutes (string->number (cadr components)))) (+ hours minutes))) (define (item-effort item) (effort->minutes (item-property item "Effort")))
+end_src
Available priorities as a list. Each list item should be just a single uppercase letter.
+begin_src scheme
(defvar org-priorities '("A" "B" "C" "D" "E" "F") "A list of priorites from which the user can select. The order here is how they will be displayed, but don't affect the order when creating the agenda.")
+end_src
+begin_src scheme
(defvar org-use-tag-inheritance #t "Whether or not tags are inherited for the purposes of search and filter. By default this is true.")
+end_src
+begin_src scheme
(defvar org-log-done 'time "What to do when the state of an item is changed to a done state. This can be either 'time (to add a CLOSED line with a timestamp) or #f")
(defvar org-log-repeat 'time "What to do when the state of a repeated item is changed to a done state. This can be either 'time (to log the state change) before going back to a todo state or #f")
(defvar org-todo-repeat-to-state #f "Set this to a state, e.g. TODO, if you want a task state to be reset to something specific when marked as done and there is a repeat modifier on a date.")
(defvar org-log-into-drawer #f "The name of the drawer to log state changes and clock/timer entries to. If set to #f then don't log state changes into a drawer. A sensible name for this is LOGBOOK.")
(defvar org-log-done-transition #t "If #t then log a state change to a done state. This will only work if modifying an existing item.")
(defvar org-repeat-update-show-banner #t "Set this to #f if you would rather than have a banner shown telling you of the new date for a repeating item when the state is set to done.")
+end_src
+begin_src scheme
(defvar org-todo-action-keywords '() "A list of keywords to use for TODO action states. If empty then the value entered on the Settings tab is used.")
(defvar org-todo-done-keywords '() "A list of keywords to use for TODO done states. If empty then the value entered on the Settings tab is used.")
+end_src
An item template can be applied when quick capture is initiated within beorg itself (i.e. not via the extension). In the future a user interface will be implemented to allow easier definition of these templates.
+begin_src scheme
(defvar item-templates () "List of pairs, first item in pair is template name followed by template definition. Templates can also be defined using a beorg extension.")
(defvar template-allow-spec-in-url-scheme #f "If #t then the template parameter in the capture URL scheme can specify the template parameters and not just an existing template")
(define template-text-toolbar-items '(("icon-left" (backward-char)) ("icon-right" (forward-char)) ("icon-change" (show-transform-commands))))
(define template-date-toolbar-items '(("icon-help" (alert "Help" "In most cases the toolbar buttons will insert what is needed. The minimum required to specify a date is a number of days from today. For example, 0 is today. If you want tomorrow then type 1. Optionally this number can be followed by a unit - h (for hour), d (for day), m (for month), y (for year). If you want a date+time for 1 hour for now then enter 1h.\n\nAfter the relative number of hours/days/etc from now has been entered you can optionally provide a flag to say that the time should be included. For example 1t (or 1dt) means in exactly one day from now, i.e. the time is also included.\n\nFinally you can specify an absolute time. For example, 1t1300 means tomorrow at 1pm.")) ("icon-left" (backward-char)) ("icon-right" (forward-char)) ("Today" (insert "0")) ("Today+time" (insert "0t")) ("In 1 hour" (insert "1h")) ("Tomorrow" (insert "1")) ("In 1 Week" (insert "1w")) ("Today at 13:00" (insert "0t1300"))))
(define template-macro-toolbar-items '(("icon-help" (alert "Help" "There are various macros available (toolbar buttons are defined for each) which are expanded when the template is applied to a new item. For example you might want to insert the name of the current month - in which case the %monthlong% will insert January or February, etc.")) ("icon-left" (backward-char)) ("icon-right" (forward-char)) ("icon-change" (show-transform-commands)) ("Now" (insert "%now%")) ("Today" (insert "%today%")) ("Year" (insert "%year%")) ("Month, e.g. 01" (insert "%month%")) ("Month, e.g. Jan" (insert "%monthshort%")) ("Month, e.g. January" (insert "%monthlong%")) ("Week, e.g. 1" (insert "%week%")) ("Day, e.g. 18" (insert "%day%")) ("Day, e.g. Mon" (insert "%dayshort%")) ("Day, e.g. Monday" (insert "%daylong%")) ("Hour" (insert "%hour%")) ("Minute" (insert "%minute%"))))
+end_src
-
Agenda
+begin_src scheme
(defvar agenda-exclude-files () "List of files, including extension, to exclude from the agenda")
(defvar date-preset-times '("09:00" "14:00" "17:00" "21:00") "A list of pre-defined times which will be shown when you add a time to a date")
(defvar org-contacts-birthday-property "BIRTHDAY" "The name of the property to use to indicate this entry should be shown in the agenda on the specified anniversay. The value should be in the format yyyy-MM-dd")
+end_src
-
todo
+begin_src scheme
(defvar todo-exclude-files () "List of files, including extension, to exclude from the TODO list")
+end_src
Filtering
+begin_src scheme
(define filter-table (make-hashtable equal-hash equal?)) (define (filter-add name predicate) (if (and (string? name) (procedure? predicate)) (hashtable-set! filter-table name predicate) "name expected to be a string and predicate should be a procedure")) (define (filter-match name item) ((hashtable-ref filter-table name (lambda (item) #f)) item))
(defvar filter-include-default #t "Whether or not the built-in TODO filters should be shown")
(defvar filter-min-chars 3 "The minimum number of characters that need to be entered for a search string to be acted upon.")
+end_src
-
Notifications
+begin_src scheme
(defvar badge-filter "o k" "The search filter string which is used to determine the number to display on the badge. By default this uses the flags 'o' (for overdue tasks only) and 'k' (for incomplete tasks only)")
+end_src
-
Buffer handling The buffer is equivalent to the text being edited (or for the REPL the entire text shown since it started)
+begin_src scheme
;; The point is equivalent to the cursor and has a minimum value of 1 (define (point-min) 1) ;; The maximum point value is the equivalent to going to the end of the buffer (define (point-max) (1+ (buffer-size))) ;; The region is the selected text. If no text is selected then this will return an empty string (define (region) (buffer-substring (region-beginning) (region-end)))
+end_src
-
Editor ** Functions
+begin_src scheme
;; Move the point (i.e. the cursor) back one character. If already at the beginning nothing will happen. (define (backward-char) (goto-char (1- (point)))) ;; Move the point forward one character. If already at the end nothing will happen. (define (forward-char) (goto-char (1+ (point)))) ;; Used internally by beorg to execute the code attached to an item on a toolbar. (define (toolbar-run toolbar-name item) (eval (cadr (assoc item toolbar-name)))) ;; Hooks so that the editor can respond to particular key presses (define (editor-char-event char) (if (string=? char "\n") (begin (editor-newline-event) #t) #f)) (define (editor-newline-event) (org-list-continue))
+end_src
** Defaults
+begin_src scheme
(defvar editor-font "Menlo 15" "The font to use in the editor. The format is ' '. For example 'Menlo 15'.") (defvar editor-background-color "" "The hex color, e.g. 000000, to use for the text editor background. If an empty string then the color defined in the active theme will be used.") (defvar editor-text-color-default "" "The hex color, e.g. 000000, to use for the text editor background font when no syntax highlighting is applied. If an empty string then the color defined in the active theme will be used.") (defvar editor-text-color-level1 "" "The hex color, e.g. 000000, to use for the text editor for a first level headline. If an empty string then the color defined in the active theme will be used.") (define editor-text-color-level2 "") (define editor-text-color-level3 "") (define editor-text-color-level4 "") (define editor-text-color-level5 "") (define editor-text-color-level6 "")
(defvar editor-toolbar-items '(("icon-left" (backward-char)) ("icon-right" (forward-char)) ("icon-list" (insert "+ ")) ("icon-todolist" (insert "+ [ ] ")) ("icon-change" (show-transform-commands)) ("icon-tools" (show-tools-commands)) ("icon-settings" (insert-code-snippet))) "A list of buttons to show above the keyboard when editing notes. The list is a list of lists stating the button text and the code to run. For example '((\"<\" (backward-char)) (\">\" (forward-char))) defines a toolbar with the buttons < and > which respectively execute the functions backward-char and forward-char.")
(defvar editor-toolbar-show-in-mini #f "If #t then the editor toolbar will be shown in the mini editor when editing an item.")
(define sheet-current '()) (define (sheet items) (set! sheet-current items) (sheet-present (map car items))) (define (sheet-current-exec item-name) (let ((form (cadr (assoc item-name sheet-current)))) (eval form)))
(define date-picker-callback #f) (define (date-picker date includes-time callback) (set! date-picker-callback callback) (date-picker-present date includes-time)) (define (date-picker-callback-exec removed date includes-time) (if (procedure? date-picker-callback) (date-picker-callback removed date includes-time)))
(define location-get-lat-lon-callback #f) (define (location-get-lat-lon callback) (set! location-get-lat-lon-callback callback) (location-get-lat-lon-start)) (define (location-get-lat-lon-callback-exec lat lon) (if (procedure? location-get-lat-lon-callback) (location-get-lat-lon-callback lat lon)))
(define (region-text-set text) (let ((current-start (region-beginning))) (insert text) (region-set current-start (+ current-start (string-length text)))))
(define (add-prefix-to-lines prefix text) (string-concatenate (map (lambda (line) (string-concatenate (list prefix line "\n"))) (string-split text "\n"))))
(define (show-transform-commands) (if (string=? (region) "") (alert "" "No text is selected.") (sheet '(("Uppercase" (region-text-set (string-upcase (region)))) ("Lowercase" (region-text-set (string-downcase (region)))) ("To List" (region-text-set (add-prefix-to-lines "+ " (region)))) ("To Checklist" (region-text-set (add-prefix-to-lines "+ [ ] " (region)))) ("Reset Checklist" (region-text-set (regexp-replace-all "\+ \[\X\]" (region) "+ [ ]")))))))
(define (show-tools-commands) (sheet '(("Autocorrect On" (autocorrect-set! #t)) ("Autocorrect Off" (autocorrect-set! #f)))))
(define (insert-code-snippet) (insert "#+BEGIN_SRC scheme\n\n#+END_SRC\n") (goto-char (- (point) (string-length "\n#+END_SRC\n"))))
(define (org-list-continue) (let ((start-of-line (string-search-backward "\n" (buffer-substring (point-min) (point)))) (buffer-line-start (+ 2 (or start-of-line -1))) (match (string-re-search-forward "^(\s\+\-?\s+)" (buffer-substring buffer-line-start (point))))) (if (> (length match) 0) (if (> (- (point) (string-length (car match))) buffer-line-start) (insert (string-append "\n" (car match))) (let ((region-start (- (point) (string-length (car match))))) (delete-region region-start (point)) (goto-char region-start))) (insert "\n"))))
+end_src
-
Files
+BEGIN_SRC scheme
(defvar file-read-only-list '() "A list of files which should be considered read only and not to be updated by beorg - for example '(\"family.org\").") (defvar file-disable-delete #f "If set to #t then the option to delete files won't be available in beorg.")
+END_SRC
-
Outliner Fonts and colours
+BEGIN_SRC scheme
(defvar outliner-state-todo-font "Menlo-Bold 17" "The font to use for TODO state in the outliner") (defvar outliner-state-done-font "Menlo 17" "The font to use for DONE state in the outliner") (defvar outliner-state-todo-color "#628395" "The color to use for a TODO state") (defvar outliner-state-done-color "#555555" "The color to use for a DONE state") (defvar outliner-headline-font ".SFUIDisplay-Medium 17" "The font to use for the headline") (defvar outliner-headline-color "" "The color to use for the headline, leave as empty string to use color from theme") (defvar outliner-notes-font ".SFUIDisplay 17" "The font to use for the notes") (defvar outliner-notes-color "" "The color to use for the notes, leave as empty string to use color from theme")
+END_SRC
-
Keyboard shortcuts
+BEGIN_SRC scheme
;; Tab bar (define-command-title "tabbar.agenda" "Show Agenda") (define-command-title "tabbar.todo" "Show TODO") (define-command-title "tabbar.files" "Show Files") (define-command-title "tabbar.settings" "Show Settings") (define-command-title "tabbar.new" "New item") (define-command-title "tabbar.show-templates" "Templates") (define-command-title "tabbar.repl" "REPL") (define-key "tabbar" "s-1" ".agenda") (define-key "tabbar" "s-2" ".todo") (define-key "tabbar" "s-3" ".files") (define-key "tabbar" "s-4" ".settings") (define-key "tabbar" "s-n" ".new") (define-key "tabbar" "S-s-n" ".show-templates") (define-key "tabbar" "S-s-r" ".repl")
;; Agenda/TODO (define-command-title "agenda.next-item" "Next item") (define-command-title "agenda.previous-item" "Previous item") (define-command-title "agenda.open-item" "Open item") (define-command-title "agenda.toggle-search-focus" "Toggle search focus") (define-command-title "agenda.show-saved-searches" "Saved searches") (define-command-title "agenda-weekly.today" "Today") (define-command-title "agenda-weekly.next-week" "Next week") (define-command-title "agenda-weekly.previous-week" "Previous week") (define-command-title "agenda-weekly.goto-week" "Goto week") (define-key "agenda" "
" ".next-item") (define-key "agenda" " " ".previous-item") (define-key "agenda" " " ".open-item") (define-key "agenda" "s-f" ".toggle-search-focus") (define-key "agenda" "S-s-f" ".show-saved-searches") (define-key "agenda-weekly" "s-t" ".today") (define-key "agenda-weekly" "s- " ".next-week") (define-key "agenda-weekly" "s- " ".previous-week") (define-key "agenda-weekly" "s-g" ".goto-week") ;; Saved searches (define-command-title "saved-searches.done" "Dismiss") (define-command-title "saved-searches.add" "New search") (define-command-title "saved-searches.next" "Next search") (define-command-title "saved-searches.previous" "Previous search") (define-command-title "saved-searches.use" "Use selected search") (define-command-title "saved-searches.edit" "Edit selected search") (define-command-title "saved-searches.delete" "Delete selected search") (define-key "saved-searches" "
" ".done") (define-key "saved-searches" "s-n" ".add") (define-key "saved-searches" " " ".next") (define-key "saved-searches" " " ".previous") (define-key "saved-searches" " " ".use") (define-key "saved-searches" "s-e" ".edit") (define-key "saved-searches" "s-d" ".delete") ;; Files (define-command-title "files.next-file" "Next file") (define-command-title "files.previous-file" "Previous file") (define-command-title "files.open-file" "Open file") (define-command-title "files.new" "New file") (define-command-title "files.delete" "Delete file") (define-command-title "files.rename" "Rename file") (define-command-title "files.toggle-pin" "Toggle pinned status") (define-command-title "files.toggle-search-focus" "Toggle search focus") (define-key "files" "
" ".next-file") (define-key "files" " " ".previous-file") (define-key "files" " " ".open-file") (define-key "files" "S-s-n" ".new") (define-key "files" "s-d" ".delete") (define-key "files" "s-r" ".rename") (define-key "files" "s-p" ".toggle-pin") (define-key "files" "s-f" ".toggle-search-focus") ;; Item editor (define-command-title "item.save" "Save changes") (define-command-title "item.cancel" "Cancel changes") (define-command-title "item.headline" "Headline") (define-command-title "item.file" "Move file") (define-command-title "item.state" "State") (define-command-title "item.priority" "Priority") (define-command-title "item.tags" "Tags") (define-command-title "item.date-scheduled" "Scheduled date") (define-command-title "item.date-deadline" "Deadline date") (define-command-title "item.date-showon" "Show on date") (define-command-title "item.notes" "Notes") (define-key "item" "s-s" ".save") (define-key "item" "
" ".cancel") (define-key "item" "s-e" ".headline") (define-key "item" "s-r" ".file") (define-key "item" "s-1" ".state") (define-key "item" "s-2" ".priority") (define-key "item" "s-3" ".tags") (define-key "item" "s-4" ".date-scheduled") (define-key "item" "s-5" ".date-deadline") (define-key "item" "s-6" ".date-showon") (define-key "item" "s-t" ".notes") ;; Text editor (define-command-title "text-editor.save" "Save") (define-key "text-editor" "s-s" ".save")
;; Text editor toolbar (define-command-title "editor-toolbar-items.icon-list" "Start a list") (define-command-t