75 rader
1.9 KiB
EmacsLisp
75 rader
1.9 KiB
EmacsLisp
;;; utils.el --- The utility collections
|
|
;;; Version: 0.1.0
|
|
;;; Package-Version 0.1.0
|
|
;;; Commentary:
|
|
;;; Code:
|
|
|
|
(defmacro comment (&rest body)
|
|
"Ignore the given BODY."
|
|
nil)
|
|
|
|
|
|
(defun prod-p ()
|
|
"Return non-nil if we're in development mode."
|
|
(when (getenv "LXHOME_PROD")
|
|
t))
|
|
|
|
|
|
(defun get-buffer-global-props (prop)
|
|
"Get a plists of global org properties PROP of current buffer."
|
|
(car
|
|
(org-element-map
|
|
(org-element-parse-buffer)
|
|
'keyword
|
|
(lambda (el)
|
|
(when (string-match prop (org-element-property :key el))
|
|
(org-element-property :value el))))))
|
|
|
|
|
|
(defun get-file-global-props (file prop)
|
|
"Return the value of the given global PROP in the given org FILE."
|
|
(with-temp-buffer
|
|
(insert-file-contents file)
|
|
(message (get-buffer-global-props prop))))
|
|
|
|
|
|
(comment
|
|
(setq org-directory "~/src/lxhome/orgs/")
|
|
(let ((f "./orgs/index.org"))
|
|
(get-file-global-props f "CATEGORY")))
|
|
|
|
|
|
(defun ->epoch (date-str)
|
|
"Convert the given DATE-STR to epoch seconds."
|
|
;; Just because it's easier to deal with date in bash rather than elisp
|
|
(string-to-number
|
|
(shell-command-to-string (concat (format "date -d %s" date-str) " +%s"))))
|
|
|
|
|
|
(defun replace-in-buffer (str replacement)
|
|
"Replace the given STR with its REPLACEMENT in current buffer."
|
|
(with-current-buffer (current-buffer)
|
|
(goto-char (point-min))
|
|
(while (search-forward str nil t)
|
|
(replace-match replacement))))
|
|
|
|
|
|
(defun copy-template (src dest content &optional title)
|
|
"Replace the placeholder in SRC with CONTENT and write it to DEST."
|
|
(with-temp-file dest
|
|
(insert-file-contents src)
|
|
(when title
|
|
(replace-in-buffer "<<<title>>>" title))
|
|
(replace-in-buffer "<<<links>>>" content)))
|
|
|
|
|
|
(defun get-file-tags (file)
|
|
"Returna list of tags for the given FILE."
|
|
(with-temp-buffer
|
|
(insert-file-contents file)
|
|
(mapcar #'car (org-get-buffer-tags))))
|
|
|
|
|
|
(provide 'lisp/utils)
|
|
;;; utils.el ends here
|