-
Notifications
You must be signed in to change notification settings - Fork 4
/
org-status.el
153 lines (138 loc) · 5.36 KB
/
org-status.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
;;; org-status.el --- Tweet using `org-mode's capture functionality.
;; Author: Neil Smithline
;; Maintainer:
;; Copyright (C) 2012, Neil Smithline, all rights reserved.
;; Created: Sun May 27 09:24:41 2012 (-0400)
;; Version: 1.0-alpha1
;; Last-Updated:
;; By:
;; Update #: 0
;; URL: https://github.com/neil-smithline-elisp/org-status
;; Keywords: org-mode, twitter, tweet
;; Compatibility: Wherever org is.
;;
;; Features that might be required by this library:
;;
;; defhook
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;; Sorry but I'm tired. For now, see the README: http://bit.ly/MoGKYU
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Change Log:
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; 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 this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:
(require 'defhook)
(defgroup org-status nil
"Settings for `org-status-update' commands."
:group 'org)
(defcustom org-status-twitter-command "/usr/local/Cellar/ruby/1.9.3-p0/bin/t"
"Full path to the installed `t' command on your system.
See https://github.com/sferik/t for instructions on installing `t'."
:type '(file :must match t)
:risky t
:safe nil
:group 'org-status)
(defcustom org-status-output-buffer "*Org Status Output*"
"Status buffer from `org-status-update' commands."
:type 'string
:safe t
:risky nil
:group 'org-status)
(defun org-status-tweet ()
"Do a tweet for the current headline."
(beginning-of-line 1)
(let* ((status-props (org-agenda-get-some-entry-text
(point-marker) 9999))
(status (substring-no-properties status-props))
(headline (nth 4 (org-heading-components))))
(message "Tweeting %s . . ." headline)
(assert (<= (length status) 140) t)
(get-buffer-create org-status-output-buffer)
(let ((success (shell-command
(format "%s update %s"
org-status-twitter-command
(shell-quote-argument status))
org-status-output-buffer
org-status-output-buffer))
(output (substring
(save-excursion
(set-buffer org-status-output-buffer)
(buffer-substring-no-properties (point-min)
(point-max)))
(1+ (length org-status-twitter-command)))))
(if (zerop success)
(progn
(org-todo 'done)
output)
;; Remove trailing newline and period for error messages.
(let ((error-string (substring output 0 (- (length output) 2))))
(error "Error (%s): %s: `%s'"
success error-string headline))))))
(defun org-status-updates ()
"Loop through entries looking for status updates."
(interactive)
(let ((results (org-map-entries #'org-status-tweet
"TWEET+TODO=\"POST\"")))
(when results
(with-output-to-temp-buffer org-status-output-buffer
(set-buffer org-status-output-buffer)
(print-elements-of-list results)))))
(unless :COMMENT-on-hold
(defvar org-status-buffer nil
"Non-nil if `org-status-updates` shoul be run when saving this buffer.")
(make-variable-buffer-local 'org-status-buffer)
(setq-default org-status-buffer nil)
(defhook set-org-status-buffer (org-mode-hook)
(if (string-match "-status.org$" (or (buffer-file-name) ""))
(setq org-status-buffer t)
(setq org-status-buffer nil)))
(defhook org-auto-status-updates (write-file-functions)
"If local variable `org-status-buffer`, run `org-status-updates' on it."
(when org-status-buffer
(org-status-updates))
nil)
)
(defhook set-org-status-buffer (org-mode-hook)
(when (string-match "-status.org$" (or (buffer-file-name) ""))
(defhook org-auto-status-updates (write-file-functions :local t)
"Run `org-status-updates' before saving the current buffer."
(org-status-updates)
nil)))
(defun org-auto-status-updates-toggle (arg)
"Toggle `org-status-buffer' in the local buffer.
If optional ARG is positive, set `org-status-buffer' to t, if
negative, set to nil."
(interactive "p")
(let ((a (when current-prefix-arg arg)))
(cond ((null a) (setq org-status-buffer (not org-status-buffer)))
((> a 0) (setq org-status-buffer t))
(t (setq org-status-buffer nil))))
(message "org-status-buffer is %s." org-status-buffer))
(provide 'org-status)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; org-status.el ends here