legalnonsense / org-deadsync Goto Github PK
View Code? Open in Web Editor NEWSync deadlines in orgmode files
Sync deadlines in orgmode files
Hi,
This package is really coming along! You either learn very quickly or already knew much more than you let on. ;)
Here's a quick suggestion. In this function, you call ts-adjust
once for every adjustment. I doubt the performance would matter in this package, but in general, that will be slower than calling it one time, because of how it works internally. So here's another way to write it that only calls it once:
Line 108 in eb1c29f
(defun org-deadsync--ts-adjust (&rest adjustments)
"Wrapper for (ts-adjust) to allow arguments in the form, e.g., \"+3d\"; accepts a list of strings in the form \"[+/-][number][d(ay), m(onth), y(ear)]\"."
(let* ((ts (-last-item adjustments))
(adjustments (cl-loop for adj in (nbutlast adjustments)
for num = (string-to-number (substring adj 0 -1))
for slot = (pcase-exhaustive (substring adj -1)
("d" 'day)
("m" 'month)
("y" 'year))
append (list slot num))))
(apply #'ts-adjust (append adjustments (list ts)))))
Also, you don't need the if
here, as org-ql-select
returns nil if there are no results:
(defun org-deadsync--dependentsp ()
"Does the current heading have dependents?"
(when-let ((master-id (org-entry-get (point) "ID")))
(if (org-ql-select org-deadsync-files
`(and (property "ORG-DEADSYNC-LINK" ,master-id)
(property "ORG-DEADSYNC-ACTIVE" "t")))
t nil)))
So you could write it like:
(defun org-deadsync--dependentsp ()
"Return non-nil if current entry has `org-deadsync' dependents."
(when-let* ((master-id (org-entry-get (point) "ID")))
(org-ql-select org-deadsync-files
`(and (property "ORG-DEADSYNC-LINK" ,master-id)
(property "ORG-DEADSYNC-ACTIVE" "t")))))
Also, I'm not sure exactly what this function is testing:
(defun org-deadsync--deadline-locked-p ()
"For the current heading, returns t if deadline is locked; otherwise nil"
(save-excursion
(when (org-get-deadline-time (point))
(end-of-visual-line)
(re-search-backward "^\\*+[[:space:]]")
(re-search-forward "DEADLINE:[[:space:]]<[[:digit:]]\\{4\\}-[[:digit:]]\\{2\\}-[[:digit:]]\\{2\\}.*?>" nil t)
(if (text-property-any (match-beginning 0) (match-end 0) 'read-only t)
't nil))))
But generally you'd probably want to write it something like this:
(defun org-deadsync--deadline-locked-p ()
"Return non-nil if current entry has locked deadline."
(save-excursion
(when (org-entry-get (point) "DEADLINE")
(forward-line 1)
(when (re-search-forward org-deadline-line-regexp (line-end-position) t)
(text-property-any (match-beginning 0) (match-end 0) 'read-only t)))))
end-of-visual-line
is almost certainly the wrong thing to use unless you're writing code that works on the visual representation of wrapped lines. The function should be called with point on the heading, so you don't need to do that anyway. And you should avoid using re-search-backward
, because it's slower. And you must bound the search, otherwise it will also find deadline lines in other headings. Also, note the use of org-deadline-line-regexp
. Org has many such regexps in variables already. They're easy to find with Helm, e.g. C-h v org regexp
will list many.
But I'm not sure why you're checking text properties. Generally that's not the right way to check things in Org buffers. And I'm not sure what a locked deadline is.
Here's a way to simplify this function using pcase
:
(defun org-deadsync--weekend-adjust (timestamp)
"Adjust deadline to next Monday if the deadline falls on a weekend, assuming org-deadsync-weekend-adjustment is t"
(if org-deadsync-weekend-adjustment
(pcase (ts-day-abbr timestamp)
("Sun" (ts-adjust 'day 1 timestamp))
("Sat" (ts-adjust 'day 2 timestamp))
(_ timestamp))
timestamp))
But you might prefer to test the day number to avoid potential localization issues:
(defun org-deadsync--weekend-adjust (timestamp)
"Adjust deadline to next Monday if the deadline falls on a weekend, assuming org-deadsync-weekend-adjustment is t"
(if org-deadsync-weekend-adjustment
(pcase (ts-dow timestamp)
(0 (ts-adjust 'day 1 timestamp))
(6 (ts-adjust 'day 2 timestamp))
(_ timestamp))
timestamp))
By the way, if you're interested, I'd love to get your feedback on this new package: https://github.com/alphapapa/prism.el For me it makes lisp code much easier to read and understand. I tried to make the default settings look decent, but it depends on the theme, and it's very customizeable.
That is all.
If a deadline has a negative offset, then the weekend offset has to shift the date to the previous Friday rather than the following Monday.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.