1
0
Fork 0
org-cv/org-cv-utils.el

83 lines
3.2 KiB
EmacsLisp
Raw Normal View History

2019-02-02 17:50:46 +00:00
;;; org-cv-utils.el --- Common utility functions for CV exporters -*- lexical-binding: t; -*-
;; Copyright (C) 2018 Free Software Foundation, Inc.
;; Author: Oscar Najera <hi AT oscarnajera.com DOT com>
;; Keywords: org, wp, tex
;; This file is not part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;;
;; This library implements some utility functions
;;; Code:
(require 'org)
(require 'ox)
2022-08-22 12:17:04 +00:00
(require 'org-element)
2019-02-02 17:50:46 +00:00
(defun org-cv-utils-org-timestamp-to-shortdate (date_str)
2023-10-19 17:23:34 +00:00
"Format orgmode timestamp DATE_STR into a short form date.
2019-02-02 17:50:46 +00:00
Other strings are just returned unmodified
2022-08-22 12:17:04 +00:00
e.g. <2012-08-12 Mon> => Aug 2012
2019-02-02 17:50:46 +00:00
today => today"
2022-08-22 12:17:04 +00:00
(if (string-match (org-re-timestamp 'all) date_str)
(let* ((dte (org-parse-time-string date_str))
2019-02-02 17:50:46 +00:00
(month (nth 4 dte))
(year (nth 5 dte))) ;;'(02 07 2015)))
(concat
2022-08-22 12:17:04 +00:00
(calendar-month-name month 'abbreviate) " " (number-to-string year)))
2019-02-02 17:50:46 +00:00
date_str))
(defun org-cv-utils--format-time-window (from-date to-date)
"Join date strings in a time window.
2019-02-02 17:50:46 +00:00
FROM-DATE -- TO-DATE
in case TO-DATE is nil return Present.
If both dates are the same, return just FROM-DATE"
2023-10-21 20:14:27 +00:00
(let ((from (org-cv-utils-org-timestamp-to-shortdate from-date))
(to (if (not to-date) "Present"
(org-cv-utils-org-timestamp-to-shortdate to-date))))
2023-10-21 20:14:27 +00:00
(if (or (string= from to))
from
(concat from " -- " to))))
2019-02-02 17:50:46 +00:00
2020-06-01 17:54:47 +00:00
(defun org-cv-utils--parse-cventry (headline info)
2022-08-22 12:17:04 +00:00
"Return alist describing the entry in HEADLINE.
INFO is a plist used as a communication channel."
2023-10-21 19:59:00 +00:00
(let* ((title (org-export-data (org-element-property :title headline) info))
(date (org-element-property :DATE headline))
2023-10-21 20:14:27 +00:00
(from-date (or (org-element-property :FROM headline)
date
(user-error "No FROM property provided for cventry %s" title)))
2023-10-21 19:59:00 +00:00
(to-date (or (org-element-property :TO headline) date))
(host (or (org-element-property :HOST headline)
(org-element-property :ORGANIZATION headline)
(org-element-property :INSTITUTION headline)
(org-element-property :SCHOOL headline)
(org-element-property :EMPLOYER headline)
(org-element-property :EVENT headline) "")))
2020-06-01 17:54:47 +00:00
`((title . ,title)
2023-10-21 20:14:27 +00:00
(date . , (org-cv-utils--format-time-window from-date to-date))
2023-10-21 19:59:00 +00:00
(host . ,host)
(location . ,(or (org-element-property :LOCATION headline) ""))
(image . ,(org-element-property :IMAGE headline)))))
2020-06-01 17:54:47 +00:00
2019-02-02 17:50:46 +00:00
(provide 'org-cv-utils)
2022-08-22 12:17:04 +00:00
;;; org-cv-utils.el ends here