You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
5.9 KiB
EmacsLisp

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

;; variables live here
(setq dw-username "tobli")
(setq dw-pin "0397")
(setq dw-defaultlocation "🔺")
(setq dw-tagslist "~/Documents/drive/admin/emacs/tags.txt")
(setq dw-iconfile "~/Documents/drive/admin/emacs/iconchoose.el")
(setq lastfm-login t) ;; boolean
(setq log nil)
(setq logfile "~/Documents/drive/org/calendar/habit.org")
(setq lastfm-user "litrovers")
;;;;;;;;;;;;;;;;;;;;;;
(defun dwexport ()
"Export HTML for DW posting"
(let ((org-export-with-author 'nil)
(org-export-with-creator 'nil)
(org-export-with-date 'nil)
(org-export-with-section-numbers 'nil)
(org-export-time-stamp-file 'nil)
(org-export-with-toc 'nil)
(org-html-validation-link 'nil))
(org-html-export-to-html))
(setq oldname (concat (file-name-base) ".org"))
(setq newname (concat (file-name-base) ".html"))
(find-file-noselect newname)
(with-current-buffer newname
(goto-char (point-min))
(setq delpoint-one (search-forward "<body>\n"))
(delete-region (point-min) delpoint-one)
(goto-char (point-max))
(setq delpoint-two (search-backward "</body>"))
(delete-region delpoint-two (point-max))
(write-file newname)))
(defun dwdraft ()
"Export HTML for DW posting and copy it to the clipboard"
(interactive)
(dwexport)
(with-current-buffer newname
(kill-ring-save (point-min) (point-max)))
(kill-buffer newname)
(with-current-buffer oldname
(delete-file newname)))
(unless (string-equal system-type "android")
(defun dwsecurity ()
"Set security level for DW post"
(setq security (completing-read "Security (public, access, private): " '("public" "access" "private")))
(unless (equal security "")
(insert (concat "post-security: " security "\n")))))
(unless (string-equal system-type "android")
(defun dwmood ()
"Set mood for DW post"
(setq mood (completing-read "Mood: " '("accomplished" "aggravated" "amused" "angry" "annoyed" "anxious" "apathetic" "artistic" "awake" "bitchy" "blah" "blank" "bored" "bouncy" "busy" "calm" "cheerful" "chipper" "cold" "complacent" "confused" "contemplative" "content" "cranky" "crappy" "crazy" "creative" "crushed" "curious" "cynical" "depressed" "determined" "devious" "dirty" "disappointed" "discontent" "distressed" "ditzy" "dorky" "drained" "drunk" "ecstatic" "embarrassed" "energetic" "enraged" "enthralled" "envious" "exanimate" "excited" "exhausted" "flirty" "frustrated" "full" "geeky" "giddy" "giggly" "gloomy" "good" "grateful" "groggy" "grumpy" "guilty" "happy" "high" "hopeful" "horny" "hot" "hungry" "hyper" "impressed" "indescribable" "indifferent" "infuriated" "intimidated" "irate" "irritated" "jealous" "jubilant" "lazy" "lethargic" "listless" "lonely" "loved" "melancholy" "mellow" "mischievous" "moody" "morose" "naughty" "nauseated" "nerdy" "nervous" "nostalgic" "numb" "okay" "optimistic" "peaceful" "pensive" "pessimistic" "pissed off" "pleased" "predatory" "productive" "quixotic" "recumbent" "refreshed" "rejected" "rejuvenated" "relaxed" "relieved" "restless" "rushed" "sad" "satisfied" "scared" "shocked" "sick" "silly" "sleepy" "sore" "stressed" "surprised" "sympathetic" "thankful" "thirsty" "thoughtful" "tired" "touched" "uncomfortable" "weird" "working" "worried")))
(unless (equal mood "")
(insert (concat "post-mood: " mood "\n")))))
(unless (string-equal system-type "android")
(defun dwmusic ()
"Set current music for DW post"
(setq music (lastfm-user-get-recent-tracks :user lastfm-user :from 1 :to 1))
(setq music (replace-regexp-in-string (regexp-quote "\" \"") " " (format "%S" music) nil 'literal))
(sleep-for 1)
(if (not music)
(setq music "nil"))
(if (equal music "nil")
(sleep-for 0)
(insert (concat "post-music: "
(let* ((musicjunk
(format "%S" music))
(end (- (length musicjunk) 4)))
(substring musicjunk 4 end))"\n")))))
(unless (string-equal system-type "android")
(defun dwicon (thefile)
"Set icon for DW post"
(setq icon "skip")
(load-file dw-iconfile)
(with-current-buffer thefile
(iconchoose))
(if (equal icon "skip")
(sleep-for 0)
(insert (concat "post-icon: "icon "\n")))))
(unless (string-equal system-type "android")
(defun dwtags ()
"Set tags for DW post"
(setq basetags (s-split "\n" (f-read dw-tagslist) t))
(setq tagslist (completing-read-multiple "Tags: " basetags))
(setq tags (s-join "," tagslist))
(insert (concat "post-tags: org-export," tags "\n"))))
(unless (string-equal system-type "android")
(defun dwlocation ()
"Set location for DW post"
(setq location (read-string "Location: " dw-defaultlocation))
(unless (equal location "")
(insert (concat "post-location: " location "\n")))))
(unless (string-equal system-type "android")
(defun dwmusic-manual ()
"Set current music for DW post if lastfm.el not set up"
(setq music (read-string "Music: "))
(unless (equal music "")
(insert (concat "post-music: " music "\n")))))
(unless (string-equal system-type "android")
(defun dw-posted ()
"Log DW post"
(find-file-noselect logfile)
(with-current-buffer (file-name-nondirectory logfile)
(goto-char (point-min))
(re-search-forward "RECUR dw posts")
(org-shiftright)
(sleep-for 1)
(save-buffer))))
(unless (string-equal system-type "android")
(defun dwpost ()
"Post to DW"
(interactive)
(setq psubject (read-string "Post title (REQUIRED): "))
(dwexport)
(compose-mail (concat dw-username "+" dw-pin "@post.dreamwidth.org") psubject)
(with-current-buffer (concat "*unsent mail to " dw-username "*")
(dwtags)
(dwsecurity)
(dwlocation)
(dwicon newname)
(cond
(lastfm-login t (dwmusic))
((dwmusic-manual)))
(dwmood)
(insert (concat "\n"))
(insert-file-contents newname)
(message-send-and-exit))
(kill-buffer newname)
(kill-buffer (concat "*sent mail to " dw-username "*"))
(with-current-buffer oldname
(delete-file newname))
(cond
(log t (dw-posted)))))