Skipping weekends when scheduling items with org-mode
I am using the agenda feature of org-mode quite heavily to plan the things I need to do.
This includes recurring items that I need to do every day or every other day. For these,
I use the +1d
or +2d
syntax respectively. However, this sometimes causes items to being
scheduled on Saturday or Sunday, which is something I don’t want for things I do
at the office.
Interestingly, I could not find anything about scheduling items only from Mon-Fri, besides non-solutions such as “create 5 items for each day and schedule them weekly”.
So I had to come up with my own solution:
(defun my-org-hook-for-repeat-not-on-weekend()
(when (org-property-values "NO_WEEKEND")
;; Get time from item at POINT
(let* ((scheduled-time (org-get-scheduled-time (point)))
;; Convert to timestamp - required for the next step
(seconds-timestamp (time-to-seconds scheduled-time))
;; Convert to decoded time - required to find out the weekday
(decoded-time (decode-time seconds-timestamp))
;; Get weekday
(weekday (decoded-time-weekday decoded-time)))
(when (> weekday 5) ;; Saturday -> move to Sunday
(setq decoded-time
(decoded-time-add decoded-time (make-decoded-time :day 2))))
(when (> weekday 6) ;; Sunday - move to Monday
(setq decoded-time
(decoded-time-add decoded-time (make-decoded-time :day 1))))
(let ((encoded-time (encode-time decoded-time)))
(org-schedule nil encoded-time))
))
)
(add-hook 'org-todo-repeat-hook 'my-org-hook-for-repeat-not-on-weekend)
This code snippet adds a hook, which is executed whenever a repeated
item is re-scheduled. If it has the property NO_WEEKEND
, it checks the
scheduled date and moves it appropriately. Feel free to copy it
under the GPLv3 if this is useful for you.
tags: emacs
Skipping weekends when scheduling items with org-mode
I am using the agenda feature of org-mode quite heavily to plan the things I need to do.
This includes recurring items that I need to do every day or every other day. For these,
I use the +1d
or +2d
syntax respectively. However, this sometimes causes items to being
scheduled on Saturday or Sunday, which is something I don’t want for things I do
at the office.
Interestingly, I could not find anything about scheduling items only from Mon-Fri, besides non-solutions such as “create 5 items for each day and schedule them weekly”.
So I had to come up with my own solution:
(defun my-org-hook-for-repeat-not-on-weekend()
(when (org-property-values "NO_WEEKEND")
;; Get time from item at POINT
(let* ((scheduled-time (org-get-scheduled-time (point)))
;; Convert to timestamp - required for the next step
(seconds-timestamp (time-to-seconds scheduled-time))
;; Convert to decoded time - required to find out the weekday
(decoded-time (decode-time seconds-timestamp))
;; Get weekday
(weekday (decoded-time-weekday decoded-time)))
(when (> weekday 5) ;; Saturday -> move to Sunday
(setq decoded-time
(decoded-time-add decoded-time (make-decoded-time :day 2))))
(when (> weekday 6) ;; Sunday - move to Monday
(setq decoded-time
(decoded-time-add decoded-time (make-decoded-time :day 1))))
(let ((encoded-time (encode-time decoded-time)))
(org-schedule nil encoded-time))
))
)
(add-hook ‘org-todo-repeat-hook 'my-org-hook-for-repeat-not-on-weekend) ```
This code snippet adds a hook, which is executed whenever a repeated
item is re-scheduled. If it has the property NO_WEEKEND
, it checks the
scheduled date and moves it appropriately. Feel free to copy it
under the GPLv3 if this is useful for you.
tags: emacs
Skipping weekends when scheduling items with org-mode
I am using the agenda feature of org-mode quite heavily to plan the things I need to do.
This includes recurring items that I need to do every day or every other day. For these,
I use the +1d
or +2d
syntax respectively. However, this sometimes causes items to being
scheduled on Saturday or Sunday, which is something I don’t want for things I do
at the office.
Interestingly, I could not find anything about scheduling items only from Mon-Fri, besides non-solutions such as “create 5 items for each day and schedule them weekly”.
So I had to come up with my own solution:
``` (defun my-org-hook-for-repeat-not-on-weekend() (when (org-property-values “NO_WEEKEND”) ;; Get time from item at POINT (let* ((scheduled-time (org-get-scheduled-time (point))) ;; Convert to timestamp - required for the next step (seconds-timestamp (time-to-seconds scheduled-time)) ;; Convert to decoded time - required to find out the weekday (decoded-time (decode-time seconds-timestamp)) ;; Get weekday (weekday (decoded-time-weekday decoded-time)))
(when (> weekday 5) ;; Saturday -> move to Sunday
(setq decoded-time
(decoded-time-add decoded-time (make-decoded-time :day 2))))
(when (> weekday 6) ;; Sunday - move to Monday
(setq decoded-time
(decoded-time-add decoded-time (make-decoded-time :day 1))))
(let ((encoded-time (encode-time decoded-time)))
(org-schedule nil encoded-time))
))
)
(add-hook ‘org-todo-repeat-hook 'my-org-hook-for-repeat-not-on-weekend) ```
This code snippet adds a hook, which is executed whenever a repeated
item is re-scheduled. If it has the property NO_WEEKEND
, it checks the
scheduled date and moves it appropriately. Feel free to copy it
under the GPLv3 if this is useful for you.
tags: emacs
Skipping weekends when scheduling items with org-mode
I am using the agenda feature of org-mode quite heavily to plan the things I need to do.
This includes recurring items that I need to do every day or every other day. For these,
I use the +1d
or +2d
syntax respectively. However, this sometimes causes items to being
scheduled on Saturday or Sunday, which is something I don’t want for things I do
at the office.
Interestingly, I could not find anything about scheduling items only from Mon-Fri, besides non-solutions such as “create 5 items for each day and schedule them weekly”.
So I had to come up with my own solution:
```lisp (defun my-org-hook-for-repeat-not-on-weekend() (when (org-property-values “NO_WEEKEND”) ;; Get time from item at POINT (let* ((scheduled-time (org-get-scheduled-time (point))) ;; Convert to timestamp - required for the next step (seconds-timestamp (time-to-seconds scheduled-time)) ;; Convert to decoded time - required to find out the weekday (decoded-time (decode-time seconds-timestamp)) ;; Get weekday (weekday (decoded-time-weekday decoded-time)))
(when (> weekday 5) ;; Saturday -> move to Sunday
(setq decoded-time
(decoded-time-add decoded-time (make-decoded-time :day 2))))
(when (> weekday 6) ;; Sunday - move to Monday
(setq decoded-time
(decoded-time-add decoded-time (make-decoded-time :day 1))))
(let ((encoded-time (encode-time decoded-time)))
(org-schedule nil encoded-time))
))
)
(add-hook ‘org-todo-repeat-hook 'my-org-hook-for-repeat-not-on-weekend) ```
This code snippet adds a hook, which is executed whenever a repeated
item is re-scheduled. If it has the property NO_WEEKEND
, it checks the
scheduled date and moves it appropriately. Feel free to copy it
under the GPLv3 if this is useful for you.
tags: emacs
Blogging with Emacs on tilde.team
When blogging on tilde.team, I really like the small bb
utility for posting,
as it handles both WWW and Gopher easily. However, I don’t like writing my
posts over SSH - mainly because my GUI Emacs is nicer to use when it comes
to key bindings.
Therefore I decided to create a small script or similar for posting from my desktop emacs. This post contains the steps that I use, in case someone wants to do the same.
Just write markdown
As an Emacs user, I am of course heavily using org-mode. So I thought on writing my blog posts in org and export them as markdown. However, that adds some additional challenges:
- The markdown export from org creates some weird, empty HTML links in the file (reason unknown).
- The first line in the file is the title of the post, without any formatting (e.g.
#
). - The last line contains the tags. These are stored in org usually at the top.
So naturally I thought of using an elisp macro, a shell script or similar to make the required adjustments after the markdown export from org, but then I decided just to write markdown. That saves me all the headache of maintaining another piece of (very small) software.
Post over SSH
For posting the finished post over SSH, I thought of using either tramp, eshell, a regular shell script or a combination of them.
In the end, I decided that a very simple elisp snippet:
(defun blog-post() (interactive) (shell-command (format "scp %s tilde:" (buffer-file-name)) nil nil) (async-shell-command (format "ssh tilde bb post %s" (buffer-name))) )