Skip to content

Commit

Permalink
Set 'unicode_symbol_info' to true by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mvoidex committed Sep 26, 2016
1 parent cdccaed commit d2a777c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Settings/SublimeHaskell.sublime-settings
Expand Up @@ -86,7 +86,7 @@
"enable_hdevtools": true,

// Use unicode symbols info 'symbol info panel'
"unicode_symbol_info": false,
"unicode_symbol_info": true,

// hdevtools socket name or default
"hdevtools_socket": "",
Expand Down
2 changes: 0 additions & 2 deletions commands.py
Expand Up @@ -39,8 +39,6 @@ def is_in_project(view = None):

def show_declaration_info_panel(view, decl):
info = decl.detailed()
if get_setting_async('unicode_symbol_info'):
info = info.replace('=>', '\u21d2').replace('->', '\u2192').replace('::', '\u2237')
v = output_panel(view.window(), info, 'sublime_haskell_symbol_info_panel', syntax = 'HaskellSymbolInfo')
v.settings().set('result_file_regex', symbol_file_regex)
v.settings().erase('location')
Expand Down
2 changes: 0 additions & 2 deletions info_popup.py
Expand Up @@ -175,8 +175,6 @@ def create_symbol_popup(self, update = False):
if self.decl:
popup_parts.append(self.decl.popup([u'<a href="import:{0}">Add import</a>'.format(html.escape(self.decl.name))] if self.suggest_import else []))
popup_text = u''.join(popup_parts)
if get_setting_async('unicode_symbol_info'):
popup_text = popup_text.replace(html.escape('=>'), '\u21d2').replace(html.escape('->'), '\u2192').replace('::', '\u2237')
if update and self.view.is_popup_visible():
self.view.update_popup(popup_text)
else:
Expand Down
24 changes: 21 additions & 3 deletions sublime_haskell_common.py
Expand Up @@ -5,6 +5,7 @@
import os
import re
import json
import html
import sublime
import sublime_plugin
import subprocess
Expand Down Expand Up @@ -134,10 +135,9 @@ def get_haskell_command_window_view_file_project(view = None):


def head_of(l):
if len(l) > 0:
return l[0]
else:
if l is None or not len(l):
return None
return l[0]


def decode_bytes(s):
Expand Down Expand Up @@ -578,6 +578,24 @@ def wait_for_window(on_appear, seconds_to_wait=MAX_WAIT_FOR_WINDOW):
sublime.set_timeout(lambda: wait_for_window_callback(on_appear, seconds_to_wait), 0)


def use_unicode_operators(s, force = False):
"""
Set unicode symbols for some standard haskell operators
"""
if not force or get_setting_async('unicode_symbol_info'):
return s

ops = {
'->': '\u2192',
'=>': '\u21d2',
'::': '\u2237' }
ops.update(dict((html.escape(o), v) for o, v in ops.items()))
r = s
for o, v in ops.items():
r = r.replace(o, v)
return r


class SublimeHaskellOutputText(sublime_plugin.TextCommand):
"""
Helper command to output text to any view
Expand Down
20 changes: 18 additions & 2 deletions symbols.py
Expand Up @@ -374,6 +374,12 @@ def escape_text(txt):
return '<br>'.join(lines)


def unicode_operators(fn):
def wrapped(*args, **kwargs):
return use_unicode_operators(fn(*args, **kwargs))
return wrapped


class Declaration(Symbol):
def __init__(self, name, decl_type = 'declaration', docs = None, imported = [], defined = None, position = None, module = None):
super(Declaration, self).__init__(decl_type, name)
Expand Down Expand Up @@ -435,6 +441,7 @@ def brief(self, short = False):
def qualified_name(self):
return '.'.join([self.module_name(), self.name])

@unicode_operators
def detailed(self):
""" Detailed info for use in Symbol Info command """
parts = [self.brief()]
Expand All @@ -461,6 +468,7 @@ def detailed(self):

return '\n'.join(parts)

@unicode_operators
def popup_brief(self):
""" Brief info on popup with name, possibly with link if have source location """
info = u'<span class="function">{0}</span>'.format(html.escape(self.name, quote = False))
Expand All @@ -469,6 +477,7 @@ def popup_brief(self):
else:
return info

@unicode_operators
def popup(self, comments = []):
""" Full info on popup with docs """
parts = [u'<p>']
Expand Down Expand Up @@ -511,10 +520,9 @@ def format_type(expr):
Format type expression for popup
Set span 'type' for types and 'tyvar' for type variables
"""

if not expr:
return expr
m = re.search(r'([a-zA-Z]\w*)|(->|=>|::)', expr)
m = re.search(r'([a-zA-Z]\w*)|(->|=>|::|\u2192|\u21d2|\u2237)', expr)
if m:
e = expr[m.start():m.end()]
expr_class = ''
Expand All @@ -536,14 +544,17 @@ def __init__(self, name, function_type, docs = None, imported = [], defined = No
super(Function, self).__init__(name, 'function', docs, imported, defined, position, module)
self.type = function_type

@unicode_operators
def suggest(self):
return (u'{0} :: {1}\t{2}'.format(wrap_operator(self.name), self.type, self.imported_from_name()), self.name)

@unicode_operators
def brief(self, short = False):
if short:
return u'{0}'.format(wrap_operator(self.name))
return u'{0} :: {1}'.format(wrap_operator(self.name), self.type if self.type else u'?')

@unicode_operators
def popup_brief(self):
info = u'<span class="function">{0}</span>'.format(html.escape(self.name, quote = False))
if self.has_source_location():
Expand All @@ -561,9 +572,11 @@ def __init__(self, name, decl_type, context, args, definition = None, docs = Non
self.args = args
self.definition = definition

@unicode_operators
def suggest(self):
return (u'{0} {1}\t{2}'.format(self.name, ' '.join(self.args), self.imported_from_name()), self.name)

@unicode_operators
def brief(self, short = False):
if short:
brief_parts = [self.what, self.name]
Expand All @@ -587,6 +600,7 @@ def brief(self, short = False):

return u' '.join(brief_parts)

@unicode_operators
def popup_brief(self):
parts = [u'<span class="keyword">{0}</span>'.format(html.escape(self.what, quote = False))]
if self.context:
Expand Down Expand Up @@ -771,11 +785,13 @@ def to_region(self, view):
def from_region(self, view, rgn):
self.corrector.from_region(view, rgn)

@unicode_operators
def detailed(self):
if self.corrector.contents:
return u'\u2014 {0}\n Why not:\n\n{1}'.format(self.message, self.corrector.contents)
return u'\u2014 {0}'.format(self.message)

@unicode_operators
def popup(self):
parts = [u'<span class="message">— {0} (<a href="{1}">{2}</a>)</span>'.format(html.escape(self.message), html.escape("autofix:" + self.corrector.region.to_string()), "autofix")]
if self.corrector.contents:
Expand Down

0 comments on commit d2a777c

Please sign in to comment.