2b37786c6a97

Update
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Fri, 08 Sep 2017 19:37:36 -0400
parents c885ce38afce
children a8431e53b8bd 15bd14518a98
branches/tags (none)
files .hgsubstate vim/custom-dictionary.utf-8.add vim/vimrc weechat/python/autoload/wee_slack.py

Changes

--- a/.hgsubstate	Fri Aug 18 12:19:37 2017 -0400
+++ b/.hgsubstate	Fri Sep 08 19:37:36 2017 -0400
@@ -29,7 +29,7 @@
 10d6c6b52fcdd12f3ba457126f66fee4ccceec04 vim/bundle/securemodelines
 b4398689f7483b01684044ab6b55bf369744c9b3 vim/bundle/sexp
 e02c3e218c51c1e2ea1821a3fe412d4e09ca1502 vim/bundle/shaderhighlight
-287437b3bb6c4f21b4ed98443ede19db2a5b979c vim/bundle/splice
+062b18eebd153c13e6f36577707acb17893cd959 vim/bundle/splice
 26fbdd7d1f1aa5600d2ebf39bbdd292c38aac16e vim/bundle/strftimedammit
 2d05440ad23f97a7874ebd9b5de3a0e65d25d85c vim/bundle/surround
 19c3d966440b6cfe8d74251881a48e961ddb8648 vim/bundle/swig
@@ -37,5 +37,5 @@
 f6f2d6618a321f5b0065586a7bc934325fec81ab vim/bundle/targets
 5d5c71044880443035e07009497962feacb56b20 vim/bundle/vimtex
 bf3fd7f67e730f93765bd3c1cfcdb18fd4043521 vim/bundle/vitality
-9da28e2ecf954a705aa9f00f37e206ee7bc09101 vim/bundle/vlime
+d091242de628c09b3ff47e1c67e7cecff39adc44 vim/bundle/vlime
 6876fe38b33732cb124d415ffc4156f16da5e118 vim/bundle/windowswap
--- a/vim/custom-dictionary.utf-8.add	Fri Aug 18 12:19:37 2017 -0400
+++ b/vim/custom-dictionary.utf-8.add	Fri Sep 08 19:37:36 2017 -0400
@@ -217,3 +217,7 @@
 maintainership
 GDL
 ZDD
+HDMI
+Macbook
+Topre
+Realforce
--- a/vim/vimrc	Fri Aug 18 12:19:37 2017 -0400
+++ b/vim/vimrc	Fri Sep 08 19:37:36 2017 -0400
@@ -596,6 +596,8 @@
     let s = ""
 
     if a:winnr == winnr()
+        let errors = SyntasticStatuslineFlag()
+
         let s .= "%#GWStatusLineMode#"
         let s .= " "
         let s .= "%{StatusLineMode()}"
@@ -603,6 +605,12 @@
         let s .= "%#GWStatusLineModeX#"
         let s .= "⮀ "
 
+        if strlen(errors) != 0
+            let s .= "%#Error#"
+            let s .= errors
+            let s .= "%#GWStatusLineModeX# "
+        endif
+
         let s .= "%f"
         let s .= " %m%r%h%w"
         let s .= "%="
@@ -1169,8 +1177,10 @@
     " Force omnicompletion (vlime's)
     au FileType lisp inoremap <c-n> <c-x><c-o>
 
-    au FileType lisp setlocal iskeyword+=!,?,%
-    au FileType lisp setlocal equalprg=lispindent
+    " lol, vim ignores indentexpr if lisp is set
+    au FileType lisp setlocal nolisp
+    au FileType lisp setlocal iskeyword+=!,?,%,-
+    " au FileType lisp setlocal equalprg=lispindent
 
     " scratch buffer
     au FileType lisp nnoremap <buffer> <leader><tab> :e scratch.lisp<cr>
@@ -1182,7 +1192,7 @@
     au FileType lisp nnoremap <buffer> <silent> <localleader>Oa :call OpenLispReplABCL()<cr>
 
     " Misc mappings
-    au FileType lisp nnoremap <buffer> gi :call IndentToplevelLispForm()<cr>
+    " au FileType lisp nnoremap <buffer> gi :call IndentToplevelLispForm()<cr>
     au FileType lisp nnoremap <buffer> <localleader>h :call HyperspecLispExpression(0)<cr>
     au FileType lisp nnoremap <buffer> <localleader>H :call HyperspecLispExpression(1)<cr>
     au FileType lisp nnoremap <buffer> <silent> <localleader>q :call QuickloadLispSystem()<cr>
@@ -2582,6 +2592,8 @@
             \ "SPEED": 1
             \ }
 
+" let g:vlime_indent_keywords = {"foo": 2}
+
 function! CleanVlimeWindows()
     call vlime#plugin#CloseWindow("preview")
     call vlime#plugin#CloseWindow("notes")
@@ -2597,8 +2609,9 @@
 augroup CustomVlimeInputBuffer
     autocmd!
     " autocmd FileType vlime_input inoremap <silent> <buffer> <tab> <c-r>=VlimeKey("tab")<cr>
+    "
     autocmd FileType vlime_input setlocal omnifunc=vlime#plugin#CompleteFunc
-    " autocmd FileType vlime_input setlocal indentexpr=VlimeCalcCurIndent()
+    autocmd FileType vlime_input setlocal indentexpr=vlime#plugin#CalcCurIndent()
     autocmd FileType vlime_input inoremap <c-n> <c-x><c-o>
 augroup end
 
@@ -2615,6 +2628,8 @@
     au FileType lisp nnoremap <buffer> <localleader>S :call vlime#plugin#SendToREPL(vlime#ui#CurTopExpr())<cr>
     au FileType lisp nnoremap <buffer> <localleader>i :call vlime#plugin#Inspect(vlime#ui#CurExprOrAtom())<cr>
     au FileType lisp nnoremap <buffer> M :call vlime#plugin#DocumentationSymbol(vlime#ui#CurAtom())<cr>
+    au FileType lisp setlocal indentexpr=vlime#plugin#CalcCurIndent()
+    au FileType lisp nnoremap <buffer> gi :call IndentToplevelLispForm()<cr>
 
     " Keys for the REPL
     au FileType vlime_repl      nnoremap <buffer> i :call vlime#ui#repl#InspectCurREPLPresentation()<cr>
--- a/weechat/python/autoload/wee_slack.py	Fri Aug 18 12:19:37 2017 -0400
+++ b/weechat/python/autoload/wee_slack.py	Fri Sep 08 19:37:36 2017 -0400
@@ -56,6 +56,7 @@
         "join": "channels.join",
         "leave": "groups.leave",
         "mark": "groups.mark",
+        "info": "groups.info"
     },
     "thread": {
         "history": None,
@@ -609,15 +610,17 @@
     eventrouter = eval(signal)
     channel = eventrouter.weechat_controller.get_channel_from_buffer_ptr(buffer_ptr)
     if not channel:
-        return w.WEECHAT_RC_OK_EAT
+        return w.WEECHAT_RC_ERROR
 
     reaction = re.match("^\s*(\d*)(\+|-):(.*):\s*$", data)
+    substitute = re.match("^(\d*)s/", data)
     if reaction:
         if reaction.group(2) == "+":
             channel.send_add_reaction(int(reaction.group(1) or 1), reaction.group(3))
         elif reaction.group(2) == "-":
             channel.send_remove_reaction(int(reaction.group(1) or 1), reaction.group(3))
-    elif data.startswith('s/'):
+    elif substitute:
+        msgno = int(substitute.group(1) or 1)
         try:
             old, new, flags = re.split(r'(?<!\\)/', data)[1:]
         except ValueError:
@@ -627,11 +630,11 @@
             # rid of escapes.
             new = new.replace(r'\/', '/')
             old = old.replace(r'\/', '/')
-            channel.edit_previous_message(old, new, flags)
+            channel.edit_nth_previous_message(msgno, old, new, flags)
     else:
         channel.send_message(data)
         # this is probably wrong channel.mark_read(update_remote=True, force=True)
-    return w.WEECHAT_RC_ERROR
+    return w.WEECHAT_RC_OK
 
 
 def buffer_switch_callback(signal, sig_type, data):
@@ -696,7 +699,7 @@
         if typing_timer + 4 < now:
             current_buffer = w.current_buffer()
             channel = EVENTROUTER.weechat_controller.buffers.get(current_buffer, None)
-            if channel:
+            if channel and channel.type != "thread":
                 identifier = channel.identifier
                 request = {"type": "typing", "channel": identifier}
                 channel.team.send_to_websocket(request, expect_reply=False)
@@ -974,6 +977,7 @@
             self.channel_buffer = w.buffer_new("{}".format(self.preferred_name), "buffer_input_callback", "EVENTROUTER", "", "")
             self.eventrouter.weechat_controller.register_buffer(self.channel_buffer, self)
             w.buffer_set(self.channel_buffer, "localvar_set_type", 'server')
+            w.buffer_set(self.channel_buffer, "localvar_set_nick", self.nick)
             if w.config_string(w.config_get('irc.look.server_buffer')) == 'merge_with_core':
                 w.buffer_merge(self.channel_buffer, w.buffer_search_main())
             w.buffer_set(self.channel_buffer, "nicklist", "1")
@@ -1080,6 +1084,14 @@
             dbg("Unexpected error: {}\nSent: {}".format(sys.exc_info()[0], data))
             self.set_connected()
 
+    def update_member_presence(self, user, presence):
+        user.presence = presence
+
+        for c in self.channels:
+            c = self.channels[c]
+            if user.id in c.members:
+                c.update_nicklist(user.id)
+
 
 class SlackChannel(object):
     """
@@ -1111,6 +1123,7 @@
         # short name relates to the localvar we change for typing indication
         self.current_short_name = self.name
         self.update_nicklist()
+        self.unread_count_display = 0
 
     def __eq__(self, compare_str):
         if compare_str == self.slack_name or compare_str == self.formatted_name() or compare_str == self.formatted_name(style="long_default"):
@@ -1136,6 +1149,14 @@
                 return True
         return False
 
+    def set_unread_count_display(self, count):
+        self.unread_count_display = count
+        for c in range(self.unread_count_display):
+            if self.type == "im":
+                w.buffer_set(self.channel_buffer, "hotlist", "2")
+            else:
+                w.buffer_set(self.channel_buffer, "hotlist", "1")
+
     def formatted_name(self, style="default", typing=False, **kwargs):
         if config.channel_name_typing_indicator:
             if not typing:
@@ -1174,9 +1195,6 @@
         self.create_buffer()
         self.active = True
         self.get_history()
-        if "info" in SLACK_API_TRANSLATOR[self.type]:
-            s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["info"], {"name": self.identifier}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
-            self.eventrouter.receive(s)
         # self.create_buffer()
 
     def check_should_open(self, force=False):
@@ -1221,6 +1239,7 @@
             else:
                 w.buffer_set(self.channel_buffer, "localvar_set_type", 'channel')
             w.buffer_set(self.channel_buffer, "localvar_set_channel", self.formatted_name())
+            w.buffer_set(self.channel_buffer, "localvar_set_nick", self.team.nick)
             w.buffer_set(self.channel_buffer, "short_name", self.formatted_name(style="sidebar", enable_color=True))
             self.render_topic()
             self.eventrouter.weechat_controller.set_refresh_buffer_list(True)
@@ -1231,22 +1250,16 @@
                 w.buffer_set(self.channel_buffer, "localvar_set_server", self.team.preferred_name)
         # else:
         #    self.eventrouter.weechat_controller.register_buffer(self.channel_buffer, self)
-            try:
-                for c in range(self.unread_count_display):
-                    if self.type == "im":
-                        w.buffer_set(self.channel_buffer, "hotlist", "2")
-                    else:
-                        w.buffer_set(self.channel_buffer, "hotlist", "1")
-                else:
-                    pass
-                    # dbg("no unread in {}".format(self.name))
-            except:
-                pass
-
         self.update_nicklist()
-        # dbg("exception no unread count")
-        # if self.unread_count != 0 and not self.muted:
-        #    w.buffer_set(self.channel_buffer, "hotlist", "1")
+
+        if "info" in SLACK_API_TRANSLATOR[self.type]:
+            s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["info"], {"channel": self.identifier}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
+            self.eventrouter.receive(s)
+
+        if self.type == "im":
+            if "join" in SLACK_API_TRANSLATOR[self.type]:
+                s = SlackRequest(self.team.token, SLACK_API_TRANSLATOR[self.type]["join"], {"user": self.user, "return_im": "true"}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
+                self.eventrouter.receive(s)
 
     def destroy_buffer(self, update_remote):
         if self.channel_buffer is not None:
@@ -1334,8 +1347,8 @@
         modify_buffer_line(self.channel_buffer, text, ts.major, ts.minor)
         return True
 
-    def edit_previous_message(self, old, new, flags):
-        message = self.my_last_message()
+    def edit_nth_previous_message(self, n, old, new, flags):
+        message = self.my_last_message(n)
         if new == "" and old == "":
             s = SlackRequest(self.team.token, "chat.delete", {"channel": self.identifier, "ts": message['ts']}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
             self.eventrouter.receive(s)
@@ -1348,11 +1361,13 @@
                 s = SlackRequest(self.team.token, "chat.update", {"channel": self.identifier, "ts": message['ts'], "text": new_message}, team_hash=self.team.team_hash, channel_identifier=self.identifier)
                 self.eventrouter.receive(s)
 
-    def my_last_message(self):
+    def my_last_message(self, msgno):
         for message in reversed(self.sorted_message_keys()):
             m = self.messages[message]
             if "user" in m.message_json and "text" in m.message_json and m.message_json["user"] == self.team.myidentifier:
-                return m.message_json
+                msgno -= 1
+                if msgno == 0:
+                    return m.message_json
 
     def is_visible(self):
         return w.buffer_get_integer(self.channel_buffer, "hidden") == 0
@@ -1458,13 +1473,12 @@
         w.buffer_set(self.channel_buffer, "nicklist", "1")
         # create nicklists for the current channel if they don't exist
         # if they do, use the existing pointer
-        # TODO: put this back for mithrandir
-        # here = w.nicklist_search_group(self.channel_buffer, '', NICK_GROUP_HERE)
-        # if not here:
-        #    here = w.nicklist_add_group(self.channel_buffer, '', NICK_GROUP_HERE, "weechat.color.nicklist_group", 1)
-        # afk = w.nicklist_search_group(self.channel_buffer, '', NICK_GROUP_AWAY)
-        # if not afk:
-        #    afk = w.nicklist_add_group(self.channel_buffer, '', NICK_GROUP_AWAY, "weechat.color.nicklist_group", 1)
+        here = w.nicklist_search_group(self.channel_buffer, '', NICK_GROUP_HERE)
+        if not here:
+           here = w.nicklist_add_group(self.channel_buffer, '', NICK_GROUP_HERE, "weechat.color.nicklist_group", 1)
+        afk = w.nicklist_search_group(self.channel_buffer, '', NICK_GROUP_AWAY)
+        if not afk:
+           afk = w.nicklist_add_group(self.channel_buffer, '', NICK_GROUP_AWAY, "weechat.color.nicklist_group", 1)
 
         if user and len(self.members) < 1000:
             user = self.team.users[user]
@@ -1472,9 +1486,11 @@
             # since this is a change just remove it regardless of where it is
             w.nicklist_remove_nick(self.channel_buffer, nick)
             # now add it back in to whichever..
+            nick_group = afk
+            if self.team.is_user_present(user.identifier):
+                nick_group = here
             if user.identifier in self.members:
-                w.nicklist_add_nick(self.channel_buffer, "", user.name, user.color_name, "", "", 1)
-            # w.nicklist_add_nick(self.channel_buffer, here, user.name, user.color_name, "", "", 1)
+                w.nicklist_add_nick(self.channel_buffer, nick_group, user.name, user.color_name, "", "", 1)
 
         # if we didn't get a user, build a complete list. this is expensive.
         else:
@@ -1484,11 +1500,14 @@
                         user = self.team.users[user]
                         if user.deleted:
                             continue
-                        w.nicklist_add_nick(self.channel_buffer, "", user.name, user.color_name, "", "", 1)
-                        # w.nicklist_add_nick(self.channel_buffer, here, user.name, user.color_name, "", "", 1)
+                        nick_group = afk
+                        if self.team.is_user_present(user.identifier):
+                            nick_group = here
+                        w.nicklist_add_nick(self.channel_buffer, nick_group, user.name, user.color_name, "", "", 1)
                 except Exception as e:
                     dbg("DEBUG: {} {} {}".format(self.identifier, self.name, e))
             else:
+                w.nicklist_remove_all(self.channel_buffer)
                 for fn in ["1| too", "2| many", "3| users", "4| to", "5| show"]:
                     w.nicklist_add_group(self.channel_buffer, '', fn, w.color('white'), 1)
 
@@ -1765,6 +1784,7 @@
             self.channel_buffer = w.buffer_new(self.formatted_name(style="long_default"), "buffer_input_callback", "EVENTROUTER", "", "")
             self.eventrouter.weechat_controller.register_buffer(self.channel_buffer, self)
             w.buffer_set(self.channel_buffer, "localvar_set_type", 'channel')
+            w.buffer_set(self.channel_buffer, "localvar_set_nick", self.parent_message.team.nick)
             w.buffer_set(self.channel_buffer, "localvar_set_channel", self.formatted_name())
             w.buffer_set(self.channel_buffer, "short_name", self.formatted_name(style="sidebar", enable_color=True))
             time_format = w.config_string(w.config_get("weechat.look.buffer_time_format"))
@@ -1891,7 +1911,7 @@
     def get_sender(self):
         name = ""
         name_plain = ""
-        if 'bot_id' in self.message_json and self.message_json['bot_id'] is not None:
+        if self.message_json.get('bot_id') in self.team.bots:
             name = "{} :]".format(self.team.bots[self.message_json["bot_id"]].formatted_name())
             name_plain = "{}".format(self.team.bots[self.message_json["bot_id"]].formatted_name(enable_color=False))
         elif 'user' in self.message_json:
@@ -2085,7 +2105,28 @@
 
     # self.identifier = self.domain
 
-
+def handle_channelsinfo(channel_json, eventrouter, **kwargs):
+    request_metadata = pickle.loads(channel_json["wee_slack_request_metadata"])
+    team = eventrouter.teams[request_metadata.team_hash]
+    channel = team.channels[request_metadata.channel_identifier]
+    unread_count_display = channel_json['channel']['unread_count_display']
+    channel.set_unread_count_display(unread_count_display)
+
+def handle_groupsinfo(group_json, eventrouter, **kwargs):
+    request_metadata = pickle.loads(group_json["wee_slack_request_metadata"])
+    team = eventrouter.teams[request_metadata.team_hash]
+    group = team.channels[request_metadata.channel_identifier]
+    unread_count_display = group_json['group']['unread_count_display']
+    group_id = group_json['group']['id']
+    group.set_unread_count_display(unread_count_display)
+
+def handle_imopen(im_json, eventrouter, **kwargs):
+    request_metadata = pickle.loads(im_json["wee_slack_request_metadata"])
+    team = eventrouter.teams[request_metadata.team_hash]
+    im = team.channels[request_metadata.channel_identifier]
+    unread_count_display = im_json['channel']['unread_count_display']
+    im.set_unread_count_display(unread_count_display)
+ 
 def handle_groupshistory(message_json, eventrouter, **kwargs):
     handle_history(message_json, eventrouter, **kwargs)
 
@@ -2125,7 +2166,10 @@
 
 
 def process_presence_change(message_json, eventrouter, **kwargs):
-    kwargs["user"].presence = message_json["presence"]
+    if "user" in kwargs:
+        user = kwargs["user"]
+        team = kwargs["team"]
+        team.update_member_presence(user, message_json["presence"])
 
 
 def process_pref_change(message_json, eventrouter, **kwargs):
@@ -2302,9 +2346,9 @@
 
 
 def subprocess_channel_topic(message_json, eventrouter, channel, team):
-    text = unfurl_refs(message_json["text"], ignore_alt_text=False)
+    text = unhtmlescape(unfurl_refs(message_json["text"], ignore_alt_text=False))
     channel.buffer_prnt(w.prefix("network").rstrip(), text, message_json["ts"], tagset="muted")
-    channel.render_topic(message_json["topic"])
+    channel.render_topic(unhtmlescape(message_json["topic"]))
 
 
 def process_reply(message_json, eventrouter, **kwargs):
@@ -2473,10 +2517,7 @@
         text += unfurl_refs(unwrap_attachments(message_json, text_before), ignore_alt_text=config.unfurl_ignore_alt_text)
 
         text = text.lstrip()
-        text = text.replace("\t", "    ")
-        text = text.replace("&lt;", "<")
-        text = text.replace("&gt;", ">")
-        text = text.replace("&amp;", "&")
+        text = unhtmlescape(text.replace("\t", "    "))
         if message_json.get('mrkdwn', True):
             text = render_formatting(text)
 
@@ -2495,9 +2536,16 @@
     usernames = team.get_username_map()
     channels = team.get_channel_map()
     message = (message
+        # Replace IRC formatting chars with Slack formatting chars.
         .replace('\x02', '*')
         .replace('\x1D', '_')
         .replace('\x1F', config.map_underline_to)
+        # Escape chars that have special meaning to Slack. Note that we do not
+        # (and should not) perform full HTML entity-encoding here.
+        # See https://api.slack.com/docs/message-formatting for details.
+        .replace('&', '&amp;')
+        .replace('<', '&lt;')
+        .replace('>', '&gt;')
         .split(' '))
     for item in enumerate(message):
         targets = re.match('^\s*([@#])([\w.-]+[\w. -])(\W*)', item[1])
@@ -2559,6 +2607,12 @@
     return display_text
 
 
+def unhtmlescape(text):
+    return text.replace("&lt;", "<") \
+               .replace("&gt;", ">") \
+               .replace("&amp;", "&")
+
+
 def unwrap_attachments(message_json, text_before):
     attachment_text = ''
     a = message_json.get("attachments", None)
@@ -2811,14 +2865,17 @@
     dbg("msg_command_cb")
     aargs = args.split(None, 2)
     who = aargs[1]
-    command_talk(data, current_buffer, who)
+    if who == "*":
+        who = EVENTROUTER.weechat_controller.buffers[current_buffer].slack_name
+    else:
+        command_talk(data, current_buffer, who)
 
     if len(aargs) > 2:
         message = aargs[2]
         team = EVENTROUTER.weechat_controller.buffers[current_buffer].team
         cmap = team.get_channel_map()
         if who in cmap:
-            channel = team.channels[cmap[channel]]
+            channel = team.channels[cmap[who]]
             channel.send_message(message)
     return w.WEECHAT_RC_OK_EAT
 
@@ -3069,7 +3126,7 @@
 
         profile = {"status_text":text,"status_emoji":emoji}
 
-        s = SlackRequest(team.token, "users.profile.set", {"profile": profile}, team_hash=team.team_hash, channel_identifier=channel.identifier)
+        s = SlackRequest(team.token, "users.profile.set", {"profile": profile}, team_hash=team.team_hash)
         EVENTROUTER.receive(s)