Re: python 2 remnants: create an issue for each or...?

2019-11-19 Thread Edward K. Ream
On Tue, Nov 19, 2019 at 12:34 PM Matt Wilkie  wrote:

> I noticed a function[0] today that was created to simulate python 3, which
> is no longer necessary now that py2 support has been dropped. There's
> probably dozens of these scattered throughout. How should they be flagged
> for refactoring and/or removal? Create an issue for each one or collect
> them into one, or something else?
>

Please collect them in a single issue.  Not all can be fixed, because the
wrapper function doesn't do exactly the same thing as the actual python
function.

Having said that, I definitely do want to clean what can be cleaned.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/CAMF8tS1F1%2BvNhYkYoQtMc71duEwPSFz4NKwV2%3DTQnA90HK4WkA%40mail.gmail.com.


python 2 remnants: create an issue for each or...?

2019-11-19 Thread Matt Wilkie
I noticed a function[0] today that was created to simulate python 3, which 
is no longer necessary now that py2 support has been dropped. There's 
probably dozens of these scattered throughout. How should they be flagged 
for refactoring and/or removal? Create an issue for each one or collect 
them into one, or something else?

[0] LeoPyRef.leo#Code-->Core classes-->@file 
leoGlobals.py-->g.Scripting-->g.exec_file

-matt

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/ede23912-621e-442a-b504-9b939a0847ff%40googlegroups.com.


git tip: fetching other branches from a shallow single-branch clone

2019-11-19 Thread Matt Wilkie
For some time I've been championing the use of git "shallow clones 
" when working with Leo 
in order to dramatically speed up new clones 
. 
There's a side effect though: you don't get any information about the 
branches which have current activity but weren't named when creating the 
shallow clone (unless you use --no-single-branch option, which I often 
forget).

Here's  a 
simplistic-but-works bash remedy (for Github repos only, see this 
Stack
 
Overflow thread for background):

export URL=https://github.com/leo-editor/leo-editor/branches/active
curl $URL > x.html
printf '\n-- Commands to add the remote branches to the fetch list:\n'
grep 'data-branch-name' x.html | sed -r 's/^.*data-branch-name="(.*?)"(.*$)/git 
remote set-branches --add origin \1/'
printf '\n-- Modification dates for these branches:\n'
grep 'time-ago' x.html | sed -r 's/^.*datetime="(-..-..).*$/\1/'

The script doesn't add the remotes, just tells you what commands to run in 
copy-pastable form. After adding the remotes update your local status info 
with `git fetch`.

For bash scripts on on Windows I use GitExtensions which comes with the 
MingW bash shell; see the [console] panel.

-matt

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/966b0822-de53-458f-a340-411287c18f4b%40googlegroups.com.


The Linker class has collapsed!

2019-11-19 Thread Edward K. Ream
Documentation often primes the mental pump. So it was yesterday. In this 
post  
I said:

QQQ
- The results list exists *only* to hold data to be transferred to the 
tokens list.
- Syncing the tokens and results lists is the *only* way make this transfer!
- ...significant (non-optional) tokens appear in exactly the same order in 
the two lists.
QQQ

Any time I assert that there is only one way of doing something my 
subconscious starts screaming at me ;-) Eventually, I realized that the 
notion of significant tokens could collapse the problem.  Just synchronize 
the two token lists on their significant tokens! Instantly everything 
becomes dead easy.

Here are the three main methods of the Linker class, shown in simplified 
form for clarity:

def assign_links(self, results, tokens, tree):
# Create the lists of significant tokens and results.
sig_tokens = list(filter(self.is_significant, tokens))
sig_results = list(filter(self.is_significant, results))
# Raise an exception if the two lists are not compatible.
self.check(sig_results, sig_tokens)
# Make two-way links between tokens and results.
for r, t in zip(sig_results, sig_tokens):
self.set_links(r, t, tokens)

tx = 0  # The index of the last patched token.

def set_links(self, r, t, tokens):
# Patch all previous assignable tokens.
while self.tx <= t.index:
token = tokens[self.tx]
if self.should_be_assigned(token, r.node):
# Patch the token.
token.node = r.node
# Add the token to r.node.token_list.
token_list = getattr(r.node, 'token_list', [])
r.node.token_list = token_list + [token]
self.tx += 1

def check(self, results, tokens):
n1, n2 = len(results), len(tokens)
assert n1 == n2, (n1, n2)
for r, t in zip(results, tokens):
assert r.kind == t.kind, (repr(r), repr(t))
assert self.compare_values(r, t), (repr(r), repr(t))

Subclasses may override the remaining three helper methods, shown here w/o 
docstrings:

def is_significant(self, token):
return (
token.kind in ('name', 'number') or
token.kind == 'op' and token.value != ';')

def compare_values(self, r, t):
if t.kind == 'string':
val = True # to do. Must be more lenient.
else:
val = t.value == r.value
return val

def should_be_assigned(self, token, node):
return token.kind not in ('encoding', 'endmarker', 'ws')

That's all!

*Summary*

The linker is now the simplest thing that could possibly work.

It's also more flexible.  Subclasses can define the three helper methods as 
they like.

This is the way it is written in The Book.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/b85e78b9-d8bd-4b05-8c2f-946b46969cd1%40googlegroups.com.


Re: How to make global command/button?

2019-11-19 Thread Edward K. Ream
On Tue, Nov 19, 2019 at 3:11 AM gar  wrote:

So what should I do to make [@command or @button] globally available?
>

Everything works as expected for me.  So:

1. Make sure @command or @button is a descendant of @settings in your *active
*myLeoSettings.leo file.

2. Reload leo.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/CAMF8tS0fz8dLc-AKTELokixPDabYz1PiZo8VxNQu2vpaVtTxKA%40mail.gmail.com.


How to make global command/button?

2019-11-19 Thread gar
I coded a piece of functionality that I want to be available in every leo 
project.
I thought that it'll be enough to place it under @commands/@buttons root 
into @command/@button node in the myLeoSettings, but actually it makes this 
functionality available only for myLeoSettings project. not for the rest 
tabs open.
So what should I do to make it globally available?

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/c8781c32-0b00-4ce6-bc2b-aa04ad7f2b8b%40googlegroups.com.