@@ -90,6 +90,12 @@ When non-nil, additional debug messages will be printed to the *Messages* buffer
9090(defvar pushbullet-buffer " *Pushbullet*"
9191 " Name of the Pushbullet UI buffer." )
9292
93+ (defvar pushbullet-export-buffer " *Pushbullet Export*"
94+ " Name of the Pushbullet Export buffer." )
95+
96+ (defvar-local pusbullet-pushes nil
97+ " List of fetched Pushbullet pushes." )
98+
9399(defvar-local pushbullet-cursor nil
94100 " Cursor for pagination, returned by and used in the Pushbullet API." )
95101
@@ -194,7 +200,7 @@ Returns a formatted string with timestamp, sender info, title, and body."
194200 (pushbullet)))))
195201
196202(defun pushbullet--display-push (push )
197- " Display a single Pushbullet push PUSH in the current buffer.
203+ " Display a single PUSH in the current buffer.
198204Only displays the push if it is active and has a non-empty body."
199205 (let ((active (alist-get 'active push ))
200206 (title (alist-get 'title push ))
@@ -214,20 +220,23 @@ Only displays the push if it is active and has a non-empty body."
214220 'pushbullet--delete-push )
215221 (insert " \n\n " ))))
216222
223+ (defun pushbullet--add-pushes (data )
224+ (let ((pushes (alist-get 'pushes data))
225+ (cursor (alist-get 'cursor data)))
226+ (pushbullet--log " Received %S pushes, received %S" pushbullet-limit (length pushes))
227+ (setq pushbullet-cursor cursor )
228+ (setq pushbullet-pushes (append pushbullet-pushes pushes))))
229+
217230(defun pushbullet--display-pushes (data )
218231 " Display multiple Pushbullet pushes from DATA in the UI buffer.
219- DATA should contain 'pushes' ( list of pushes) and 'cursor' ( pagination cursor) .
232+ DATA should contain a list of ' pushes' and a pagination ' cursor' .
220233Updates the buffer-local cursor for pagination and logs debug information."
221- (let* ((inhibit-read-only t )
222- (pushes (alist-get 'pushes data))
223- (cursor (alist-get 'cursor data)))
224- (pushbullet--log " Requested %S pushes, received %S" pushbullet-limit (length pushes))
225- (setq pushbullet-cursor cursor )
234+ (let ((inhibit-read-only t ))
226235 (with-current-buffer (get-buffer-create pushbullet-buffer)
227236 (mapc (lambda (push )
228237 (goto-char (point-max ))
229238 (pushbullet--display-push push ))
230- pushes))))
239+ pushbullet- pushes))))
231240
232241(defun pushbullet--format-banner ()
233242 " Format the banner header for the Pushbullet UI buffer.
@@ -251,27 +260,30 @@ loading message, and then triggers a Pushbullet update to fetch and render
251260the pushes. Once the pushes are loaded, the loading message is removed."
252261 (let ((inhibit-read-only t )
253262 (loading-message " Loading pushes...\n\n " ))
263+ (setq pushbullet-pushes nil )
254264 (erase-buffer )
255265 (insert (propertize (pushbullet--format-banner) 'face 'font-lock-function-name-face ))
256266 (setq pushbullet-content-start-marker (point-max-marker ))
257267 (insert (propertize loading-message 'face 'font-lock-comment-face ))
258268 (pushbullet-update)
259269 (pushbullet--delete-first-occurence loading-message)))
260270
271+ (defun pushbullet--next-endpoint (cursor )
272+ (if cursor (format " /pushes?limit=%d &cursor=%s " pushbullet-limit pushbullet-cursor)
273+ (format " /pushes?limit=%d " pushbullet-limit)))
274+
261275;;;### autoload
262276(defun pushbullet-update ()
263277 " Fetch and display Pushbullet pushes in the current buffer.
264278Uses pagination cursor if available to fetch additional pushes.
265279This function is called automatically when opening the Pushbullet buffer."
266280 (interactive )
267- (let ((endpoint (if pushbullet-cursor
268- (format " /pushes?limit=%d &cursor=%s " pushbullet-limit pushbullet-cursor)
269- (format " /pushes?limit=%d " pushbullet-limit))))
270- (pushbullet--request
271- " GET" endpoint nil
272- (cl-function
273- (lambda (&key data &allow-other-keys )
274- (pushbullet--display-pushes data)))))
281+ (pushbullet--request
282+ " GET" (pushbullet--next-endpoint pushbullet-cursor) nil
283+ (cl-function
284+ (lambda (&key data &allow-other-keys )
285+ (pushbullet--add-pushes data)
286+ (pushbullet--display-pushes data))))
275287 t )
276288
277289;;;### autoload
@@ -313,9 +325,37 @@ The push title is set to the current buffer's name."
313325 (error " Kill ring is empty " ))
314326 (pushbullet-send pushbullet-default-title text)))
315327
328+ ;;;### autoload
329+ (defun pushbullet-export (&optional pushes )
330+ " Export PUSHES into an Org-mode buffer.
331+ When PUSHES is nil, or when called interactively, use 'pushbullet-pushes'."
332+ (interactive )
333+ (let ((buf (get-buffer-create pushbullet-export-buffer))
334+ (pushes (or pushes pushbullet-pushes)))
335+ (with-current-buffer buf
336+ (erase-buffer )
337+ (insert " #+TITLE: Pushbullet Export\n\n " )
338+ (mapc
339+ (lambda (push )
340+ (let ((active (alist-get 'active push ))
341+ (title (alist-get 'title push ))
342+ (body (alist-get 'body push ))
343+ (url (alist-get 'url push )))
344+ (when active
345+ (if title (insert (format " * %s \n " title))
346+ (insert " * " ))
347+ (when url (insert (format " [[%s ]]\n " url)))
348+ (if body (insert (format " %s \n " body))
349+ (insert " <empty>\n " )))))
350+ pushes)
351+ (goto-char (point-min ))
352+ (org-mode ))
353+ (switch-to-buffer buf)))
354+
316355(defvar pushbullet-mode-map
317356 (let ((map (make-sparse-keymap )))
318357 (define-key map (kbd " C-c C-c" ) #'pushbullet-send )
358+ (define-key map (kbd " C-c C-e" ) #'pushbullet-export )
319359 (define-key map (kbd " C-c C-u" ) #'pushbullet-update )
320360 (define-key map (kbd " C-c C-o" ) #'browse-url-at-point )
321361 (define-key map (kbd " TAB" ) #'forward-button )
0 commit comments