double dash naming convention
This commit is contained in:
parent
0b1cd4100e
commit
25da7f5b2e
1 changed files with 51 additions and 51 deletions
102
um.el
102
um.el
|
|
@ -55,7 +55,7 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
(defcustom um-date-separator "-"
|
(defcustom um-date-separator "-"
|
||||||
"Seperator used in date strings, used by `um-date-format' and `um-date-re'."
|
"Seperator used in date strings, used by `um--date-format' and `um--date-re'."
|
||||||
:type '(string)
|
:type '(string)
|
||||||
:group 'um
|
:group 'um
|
||||||
)
|
)
|
||||||
|
|
@ -71,27 +71,27 @@
|
||||||
:group 'um
|
:group 'um
|
||||||
)
|
)
|
||||||
|
|
||||||
(defconst um-date-format (concat "%Y" um-date-separator "%m" um-date-separator "%d")
|
(defconst um--date-format (concat "%Y" um-date-separator "%m" um-date-separator "%d")
|
||||||
"Format passed to `format-time-string' when creating
|
"Format passed to `format-time-string' when creating
|
||||||
`um--header'. ISO8601 with a custom `um-date-separator'.")
|
`um--header'. ISO8601 with a custom `um-date-separator'.")
|
||||||
|
|
||||||
(defconst um-date-re (rx
|
(defconst um--date-re (rx
|
||||||
line-start
|
line-start
|
||||||
(literal ": ")
|
(literal ": ")
|
||||||
(group (repeat 4 digit)
|
(group (repeat 4 digit)
|
||||||
(literal um-date-separator)
|
(literal um-date-separator)
|
||||||
(repeat 1 2 digit)
|
(repeat 1 2 digit)
|
||||||
(literal um-date-separator)
|
(literal um-date-separator)
|
||||||
(repeat 1 2 digit))
|
(repeat 1 2 digit))
|
||||||
line-end
|
line-end
|
||||||
)
|
)
|
||||||
"um date regexp. built from `um-date-separator'."
|
"um date regexp. built from `um-date-separator'."
|
||||||
)
|
)
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;; find-file-at-point
|
;;; find-file-at-point
|
||||||
|
|
||||||
(defun um-root-path ()
|
(defun um--root-path ()
|
||||||
(or (car (seq-filter
|
(or (car (seq-filter
|
||||||
(lambda (path)
|
(lambda (path)
|
||||||
;; this way I don't have to hardcode the full path:
|
;; this way I don't have to hardcode the full path:
|
||||||
|
|
@ -115,12 +115,12 @@
|
||||||
|
|
||||||
1. `default-directory'
|
1. `default-directory'
|
||||||
2. `project-root'
|
2. `project-root'
|
||||||
3. `um-root-path'
|
3. `um--root-path'
|
||||||
"
|
"
|
||||||
(let ((dirs (list
|
(let ((dirs (list
|
||||||
default-directory
|
default-directory
|
||||||
(when (project-current) (project-root (project-current)))
|
(when (project-current) (project-root (project-current)))
|
||||||
(um-root-path)))
|
(um--root-path)))
|
||||||
dir
|
dir
|
||||||
file)
|
file)
|
||||||
(while (and dirs (not file))
|
(while (and dirs (not file))
|
||||||
|
|
@ -154,23 +154,26 @@
|
||||||
|
|
||||||
1. `default-directory'
|
1. `default-directory'
|
||||||
2. `project-root'
|
2. `project-root'
|
||||||
3. `um-root-path'
|
3. `um--root-path'
|
||||||
"
|
"
|
||||||
(or
|
(or
|
||||||
;; this does both default-directory and project-root:
|
;; this does both default-directory and project-root:
|
||||||
(funcall origfunc)
|
(funcall origfunc)
|
||||||
(let ((default-directory (um-root-path)))
|
(let ((default-directory (um--root-path)))
|
||||||
(funcall origfunc))
|
(funcall origfunc))
|
||||||
))
|
))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;; tags
|
;;; tags
|
||||||
|
|
||||||
|
(defconst um--tag-regexp "^\\+ \\([[:alpha:]\\_\\-]+\\)$"
|
||||||
|
"um tag regexp. Allows hypens and underscores within the tag.")
|
||||||
|
|
||||||
;; NOTE: this will get saved by savehist-mode
|
;; NOTE: this will get saved by savehist-mode
|
||||||
(defvar um-tags-history nil "History of inserted or searched for tags. Populates
|
(defvar um-tags-history nil "History of inserted or searched for tags. Populates
|
||||||
`completing-read'.")
|
`completing-read'.")
|
||||||
|
|
||||||
(defun um-header-current-buffer ()
|
(defun um--header-current-buffer ()
|
||||||
(car (split-string (buffer-substring-no-properties (point-min) (point-max))
|
(car (split-string (buffer-substring-no-properties (point-min) (point-max))
|
||||||
"\n\n" t
|
"\n\n" t
|
||||||
)))
|
)))
|
||||||
|
|
@ -180,9 +183,9 @@
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(search-forward "\n\n")))
|
(search-forward "\n\n")))
|
||||||
|
|
||||||
(defun um-tag-first-in-current-buffer ()
|
(defun um--tag-first-in-current-buffer ()
|
||||||
(let ((header (um-header-current-buffer)))
|
(let ((header (um--header-current-buffer)))
|
||||||
(string-match um-tag-regexp header)
|
(string-match um--tag-regexp header)
|
||||||
(match-string 1 header)
|
(match-string 1 header)
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
@ -208,7 +211,7 @@ Ultimately this relies on `xref-matches-in-files', which calls
|
||||||
;; NOTE: this means searches
|
;; NOTE: this means searches
|
||||||
;; will add to the history:
|
;; will add to the history:
|
||||||
'um-tags-history
|
'um-tags-history
|
||||||
(um-tag-first-in-current-buffer)
|
(um--tag-first-in-current-buffer)
|
||||||
)
|
)
|
||||||
"$")))
|
"$")))
|
||||||
|
|
||||||
|
|
@ -222,13 +225,13 @@ Ultimately this relies on `xref-matches-in-files', which calls
|
||||||
(let* ((bound (um--header-end-pos))
|
(let* ((bound (um--header-end-pos))
|
||||||
(found t))
|
(found t))
|
||||||
(while found
|
(while found
|
||||||
(setq found (search-forward-regexp um-tag-regexp bound t))
|
(setq found (search-forward-regexp um--tag-regexp bound t))
|
||||||
(when found (add-to-list 'tags (buffer-substring-no-properties
|
(when found (add-to-list 'tags (buffer-substring-no-properties
|
||||||
(match-beginning 1) (match-end 1))))
|
(match-beginning 1) (match-end 1))))
|
||||||
)))))
|
)))))
|
||||||
(reverse tags)))
|
(reverse tags)))
|
||||||
|
|
||||||
(defun um-tag-insert (tag)
|
(defun um--tag-insert (tag)
|
||||||
"Insert TAG as + tag\n in current buffer appending to the journal header.
|
"Insert TAG as + tag\n in current buffer appending to the journal header.
|
||||||
|
|
||||||
Emits message if TAG is already present, but does not error."
|
Emits message if TAG is already present, but does not error."
|
||||||
|
|
@ -239,7 +242,7 @@ Emits message if TAG is already present, but does not error."
|
||||||
(forward-line -1)
|
(forward-line -1)
|
||||||
(insert (concat "+ " tag "\n"))))
|
(insert (concat "+ " tag "\n"))))
|
||||||
|
|
||||||
(defun um-tag-delete (tag)
|
(defun um--tag-delete (tag)
|
||||||
"Delete TAG from the journal header in current buffer."
|
"Delete TAG from the journal header in current buffer."
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(if (search-forward (concat "+ " tag "\n") (um--header-end-pos) t)
|
(if (search-forward (concat "+ " tag "\n") (um--header-end-pos) t)
|
||||||
|
|
@ -248,24 +251,24 @@ Emits message if TAG is already present, but does not error."
|
||||||
;; shouldn't happen:
|
;; shouldn't happen:
|
||||||
(message "\"%s\" tag not found in %s" tag buffer-file-name)))
|
(message "\"%s\" tag not found in %s" tag buffer-file-name)))
|
||||||
|
|
||||||
(defun um-tag-do (tag insert)
|
(defun um--tag-do (tag insert)
|
||||||
"Insert or delete TAG from the journal header in current buffer.
|
"Insert or delete TAG from the journal header in current buffer.
|
||||||
|
|
||||||
insert when INSERT > 0, delete otherwise."
|
insert when INSERT > 0, delete otherwise."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(if (> insert 0)
|
(if (> insert 0)
|
||||||
(um-tag-insert tag)
|
(um--tag-insert tag)
|
||||||
(um-tag-delete tag))))
|
(um--tag-delete tag))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun um-tag-dwim (ARG)
|
(defun um-tag-dwim (ARG)
|
||||||
"Run `um-tag-do' on a list of filenames if region active outside
|
"Run `um--tag-do' on a list of filenames if region active outside
|
||||||
dired-mode, or if marks exist in dired-mode, or the filename at point, and
|
dired-mode, or if marks exist in dired-mode, or the filename at point, and
|
||||||
finally in the current buffer if none of those conditions match.
|
finally in the current buffer if none of those conditions match.
|
||||||
|
|
||||||
Assumes the files of interest are returned by `um-root-path'.
|
Assumes the files of interest are returned by `um--root-path'.
|
||||||
|
|
||||||
Negative prefix arg is handled by `um-tag-do', which see.
|
Negative prefix arg is handled by `um--tag-do', which see.
|
||||||
"
|
"
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
(let* (
|
(let* (
|
||||||
|
|
@ -293,8 +296,8 @@ Negative prefix arg is handled by `um-tag-do', which see.
|
||||||
(dolist (f files)
|
(dolist (f files)
|
||||||
(with-current-buffer
|
(with-current-buffer
|
||||||
;; TODO: this should use the fallback logic:
|
;; TODO: this should use the fallback logic:
|
||||||
(find-file-noselect (expand-file-name f (um-root-path)) t)
|
(find-file-noselect (expand-file-name f (um--root-path)) t)
|
||||||
(um-tag-do tag ARG)
|
(um--tag-do tag ARG)
|
||||||
(save-buffer)))
|
(save-buffer)))
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
@ -310,7 +313,7 @@ Negative prefix arg is handled by `um-tag-do', which see.
|
||||||
|
|
||||||
"
|
"
|
||||||
(insert
|
(insert
|
||||||
(format "# %s\n: %s\n\n" filename (format-time-string um-date-format)))
|
(format "# %s\n: %s\n\n" filename (format-time-string um--date-format)))
|
||||||
(when tags
|
(when tags
|
||||||
(forward-line -1)
|
(forward-line -1)
|
||||||
(dolist (tag (split-string tags ","))
|
(dolist (tag (split-string tags ","))
|
||||||
|
|
@ -335,9 +338,6 @@ A tag with a value of \"+\" is rendered as the descriptor portion of the filenam
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;; um-minor-mode : under markdown-mode
|
;;; um-minor-mode : under markdown-mode
|
||||||
|
|
||||||
(defconst um-tag-regexp "^\\+ \\([[:alpha:]\\_\\-]+\\)$"
|
|
||||||
"um tag regexp. Allows hypens and underscores within the tag.")
|
|
||||||
|
|
||||||
(defface font-lock-um-date-face
|
(defface font-lock-um-date-face
|
||||||
`((((type tty) (class mono)))
|
`((((type tty) (class mono)))
|
||||||
(t (
|
(t (
|
||||||
|
|
@ -365,11 +365,11 @@ A tag with a value of \"+\" is rendered as the descriptor portion of the filenam
|
||||||
:group 'um
|
:group 'um
|
||||||
)
|
)
|
||||||
|
|
||||||
(defvar um-minor-mode-keywords
|
(defvar um--minor-mode-keywords
|
||||||
`(
|
`(
|
||||||
(,um-date-re 1 'font-lock-um-date-face)
|
(,um--date-re 1 'font-lock-um-date-face)
|
||||||
(,um-locale-re 0 'font-lock-um-locale-face)
|
(,um-locale-re 0 'font-lock-um-locale-face)
|
||||||
(,um-tag-regexp 1 'font-lock-um-tag-face)
|
(,um--tag-regexp 1 'font-lock-um-tag-face)
|
||||||
))
|
))
|
||||||
|
|
||||||
(defvar-keymap um-minor-mode-map
|
(defvar-keymap um-minor-mode-map
|
||||||
|
|
@ -388,9 +388,9 @@ A tag with a value of \"+\" is rendered as the descriptor portion of the filenam
|
||||||
:keymap um-minor-mode-map
|
:keymap um-minor-mode-map
|
||||||
(if um-minor-mode
|
(if um-minor-mode
|
||||||
(progn
|
(progn
|
||||||
(font-lock-add-keywords nil um-minor-mode-keywords)
|
(font-lock-add-keywords nil um--minor-mode-keywords)
|
||||||
(font-lock-flush))
|
(font-lock-flush))
|
||||||
(font-lock-remove-keywords nil um-minor-mode-keywords)
|
(font-lock-remove-keywords nil um--minor-mode-keywords)
|
||||||
(font-lock-flush))
|
(font-lock-flush))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -403,20 +403,20 @@ A tag with a value of \"+\" is rendered as the descriptor portion of the filenam
|
||||||
(defun um-previous-line ()
|
(defun um-previous-line ()
|
||||||
(interactive) (move-beginning-of-line nil) (previous-line))
|
(interactive) (move-beginning-of-line nil) (previous-line))
|
||||||
|
|
||||||
(defun um-inhibit-read-only (cmd &optional args)
|
(defun um--iro (cmd &optional args)
|
||||||
(let ((inhibit-read-only t))
|
(let ((inhibit-read-only t))
|
||||||
(apply cmd args)))
|
(apply cmd args)))
|
||||||
|
|
||||||
(defun um-drag-stuff-up () (interactive) (um-inhibit-read-only 'drag-stuff-up '(1)))
|
(defun um-drag-stuff-up () (interactive) (um--iro 'drag-stuff-up '(1)))
|
||||||
(defun um-drag-stuff-down () (interactive) (um-inhibit-read-only 'drag-stuff-down '(1)))
|
(defun um-drag-stuff-down () (interactive) (um--iro 'drag-stuff-down '(1)))
|
||||||
(defun um-kill-line () (interactive) (um-inhibit-read-only 'kill-line))
|
(defun um-kill-line () (interactive) (um--iro 'kill-line))
|
||||||
(defun um-kill-region () (interactive) (um-inhibit-read-only 'kill-region '(nil nil t)))
|
(defun um-kill-region () (interactive) (um--iro 'kill-region '(nil nil t)))
|
||||||
;; NOTE: parallel to dired-copy-filename-as-kill
|
;; NOTE: parallel to dired-copy-filename-as-kill
|
||||||
(defun um-copy-line-as-kill () (interactive) (kill-ring-save (pos-bol) (pos-eol))
|
(defun um-copy-line-as-kill () (interactive) (kill-ring-save (pos-bol) (pos-eol))
|
||||||
(message (buffer-substring-no-properties (pos-bol) (pos-eol))))
|
(message (buffer-substring-no-properties (pos-bol) (pos-eol))))
|
||||||
(defun um-yank () (interactive) (um-inhibit-read-only 'yank))
|
(defun um-yank () (interactive) (um--iro 'yank))
|
||||||
(defun um-tag-dwim-inhibit-read-only (arg) (interactive "p")
|
(defun um-tag-dwim-iro (arg) (interactive "p")
|
||||||
(um-inhibit-read-only 'um-tag-dwim (list arg)))
|
(um--iro 'um-tag-dwim (list arg)))
|
||||||
|
|
||||||
;; NOTE: define-derived-mode defines a sparse keymap with the parent mode. But
|
;; NOTE: define-derived-mode defines a sparse keymap with the parent mode. But
|
||||||
;; we can prefill it:
|
;; we can prefill it:
|
||||||
|
|
@ -431,7 +431,7 @@ A tag with a value of \"+\" is rendered as the descriptor portion of the filenam
|
||||||
"C-w" 'um-kill-region
|
"C-w" 'um-kill-region
|
||||||
"w" 'um-copy-line-as-kill
|
"w" 'um-copy-line-as-kill
|
||||||
"C-y" 'um-yank
|
"C-y" 'um-yank
|
||||||
"t" 'um-tag-dwim-inhibit-read-only
|
"t" 'um-tag-dwim-iro
|
||||||
)
|
)
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue