alpha22jp / simplenote2.el

A new version of emacs helper to interact with Simplenote
GNU General Public License v2.0
58 stars 12 forks source link

Recipe: Publishing a note #44

Open emacksnotes opened 7 months ago

emacksnotes commented 7 months ago

Recipe: Publishing a note

@alpha22jp

simplenote2 doesn't provide a way to publish or unpublish a note. Fortunately, simplenote2 has necessary infrastructure for updating the published property of systemtags. It was just a matter few hours before I could come up with M-x simplenote2-publish RET and M-x simplenote2-unpublish RET to publish or unpublish a note. In simple cases, the following commands seems to work

  (defun simplenote2-publish-or-unpublish (publishp)
    "Publish or Un-Publish the current note."
    (let* ((file (buffer-file-name))
       (key (file-name-nondirectory file))
       (note-info (simplenote2--get-note-info key)))
      (cond
       (note-info
    (let ((publishp (not (not publishp))))
      (setf (nth 8 note-info) publishp)
      (setf (nth 7 note-info) t)
      (simplenote2-browser-refresh)
      (message "%sPublished" (if publishp "" "Un-"))))
       (t
    (message "This buffer is not a Simplenote note")))))

  (defun simplenote2-publish ()
    "Publish the current note."
    (interactive)
    (simplenote2-publish-or-unpublish 'publish))

  (defun simplenote2-unpublish ()
    "Un-Publish the current note."
    (interactive)
    (simplenote2-publish-or-unpublish (not 'publish)))