-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
scimax-slack.el
135 lines (111 loc) · 3.94 KB
/
scimax-slack.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
;;; scimax-slack.el --- a Slack integration for scimax and org-mode
;;; Commentary:
;; Light wrapper around the emacs-slack package to enable some org-mode integration
;; scimax-slack integration
;; https://github.com/yuya373/emacs-slack
;;
;; `slack-start' to get slack started
;;
;; It looks like you have to get a token for a workspace
(use-package slack
:commands (slack-start)
:init
(setq slack-buffer-emojify t) ;; if you want to enable emoji, default nil
(setq slack-prefer-current-team t)
:config
(slack-register-team
:name "kitchingroup"
:default t
:token (auth-source-pick-first-password :host "kitchingroup.slack.com"
:user "[email protected]")
:subscribed-channels '(general random)
:full-and-display-names t))
;; https://github.com/titaniumbones/ox-slack
;;
;; this has some export that is different than below
(require 'ox-slack)
(defhydra slack (:color blue)
"slack"
("st" slack-change-current-team "team")
("sc" slack-channel-select "channel")
("sr" slack-select-rooms "room")
("su" slack-select-unread-rooms "unread")
("si" slack-im-select "instant message"))
;; * mrkdwn exporter
;;
;; Slack seems to use some basic form of markdown with some differences. This is
;; a custom exporter to manage those:
;; 1. Put code in ```{code}```
(defun scimax-mrkdwn-src-block (src contents info)
(format "```\n%s\n```" (org-element-property :value src)))
(defun scimax-mrkdown-underline (underline contents info)
"underline not supported"
(buffer-substring (org-element-property :contents-begin underline)
(org-element-property :contents-end underline)))
(defun scimax-mrkdwn-strike-through (strike-through contents info)
(format "~%s~" (buffer-substring (org-element-property :contents-begin strike-through)
(org-element-property :contents-end strike-through))))
;; TODO
;; Images/equations
;; cite links
;; file attachments
(org-export-define-derived-backend 'scimax-mrkdwn 'md
:translate-alist '((src-block . scimax-mrkdwn-src-block)
(underline . scimax-mrkdwn-underline)
(strike-through . scimax-mrkdwn-strike-through)))
;; * Send to slack
(defun scimax-org-to-slack ()
(interactive)
"Send region or heading to a slack channel."
(let* ((team (slack-team-select))
(candidates (append (cl-loop for team in (list team)
for channels = (slack-team-channels team)
nconc channels)
(cl-loop for team in (list team)
for ims = (cl-remove-if #'(lambda (im)
(not (oref im is-open)))
(slack-team-ims team))
nconc ims)))
(room (slack-room-select candidates team))
(text (if (region-active-p)
(buffer-substring
(region-beginning)
(region-end))
(save-excursion
(save-restriction
(when (not (org-at-heading-p))
(org-previous-visible-heading 1))
(widen)
(org-narrow-to-subtree)
(buffer-string)))))
(msg (org-export-string-as text 'scimax-mrkdwn nil '(:with-toc nil :with-tags nil))))
(slack-message-send-internal msg
room
team)))
(defun slack-elfeed-entry ()
(interactive)
(let* ((title (elfeed-entry-title elfeed-show-entry))
(url (elfeed-entry-link elfeed-show-entry))
(content (elfeed-entry-content elfeed-show-entry))
(text (format-spec "Title: %t
%c
%u"
`((?t . ,title)
(?c . ,(html-to-markdown (elfeed-deref content)))
(?u . ,url))))
(msg (org-export-string-as text 'scimax-mrkdwn nil '(:with-toc nil :with-tags nil)))
(team (slack-team-select))
(candidates (append (cl-loop for team in (list team)
for channels = (slack-team-channels team)
nconc channels)
(cl-loop for team in (list team)
for ims = (cl-remove-if #'(lambda (im)
(not (oref im is-open)))
(slack-team-ims team))
nconc ims)))
(room (slack-room-select candidates team)))
(slack-message-send-internal msg
room
team)))
(provide 'scimax-slack)
;;; scimax-slack.el ends here