<div dir="auto"><div>Hi, </div><div dir="auto"><br></div><div dir="auto">I don't really do a lot of python so not sure if this will work for you, but there is a shortcut Ctrl+Alt+down/up which does some kind of scope jumping. Not sure how well it will work in a python file. For me, it allows me to jump to a function start / end quickly. </div><div dir="auto"><br></div><div dir="auto">But to really achieve what you want, I guess scripting is the only way forward at least for now. Our script api is kind of simple, and yeah there are no semantics available except for comment/string info. But it's still doable, if you want to try. </div><div dir="auto"><br></div><div dir="auto">Regarding LSP, it's a common misconception that the client has a lot semantic info available. It doesn't really, the server does and it's the server that really does all the work, the editor just does what the server says. I guess if we really try, we can accumulate some semantic info and then use that for other purposes but not sure if this will scale well or even if we want to do it. </div><div dir="auto"><br></div><div dir="auto">Lastly, it's unlikely that the external tools will allow moving cursor as the external tools are mostly meant for simple input ~ process ~ output tasks. However, allowing to execute a process via the scripting api is possible I think, but not implemented. </div><div dir="auto"><br></div><div dir="auto">All in all, I would suggest you to try the scripting api. Atm, all of Kate's indentation is implemented using the script api. </div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Mon, Feb 7, 2022, 11:29 AM Yannick Gingras <<a href="mailto:ygingras@ygingras.net">ygingras@ygingras.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In Lisp, Emacs offers a rather interesting code navigation. There are<br>
basically only 3 short-cuts that provide most of what anyone needs:<br>
- go to outer scope;<br>
- go to next item with same scope;<br>
- go to previous item with same scope.<br><br>
There might be go to inner scope, but after going outer scope, it's<br>
typically just one key stroke away to go one scope down: right arrow.<br>
<br>
Take the following example (not any real Lisp dialect):<br>
(def foo (a b c)<br>
(for (i x (enumerate (range b c))<br>
(ifeq (a x)<br>
(return i)))))<br>
<br>
What the code does is not really important, but a Python version of it<br>
would look line this:<br>
def foo(a, b, c):<br>
for i, x in enumerate(range(b, c)):<br>
if a == x:<br>
return i<br>
<br>
Besides being a great example of how mind twisting Lisp can be, it<br>
illustrate beautifully how one could take advantage of lexcical<br>
navidation. Say I just finished typing the "enumerate" clause and I<br>
want to add a default return if we don't find any `x` that is equal to<br>
`a`. I would go "outer scope" 3 times, "then next same scope" once. It<br>
would put me inside that big ugly series of closing parens: ")))))",<br>
right before the last one. I can then type Return and add my default<br>
return clause: (return nil). That's like "return None" in Python or<br>
"return null" in great many language.<br>
<br>
Kate already offers something really close to this, but not the whole<br>
solution. There is "go to matching bracket" and "previous and next<br>
matching intent", which is just like go to next item with same scope in<br>
Python. It's almost there! Wouldn't it be cool to be able to say: "I'm<br>
done with this for, I just want to add something right after it"? To do<br>
that, one would need "go to outer scope", which neither exists for<br>
brackets nor for indents, and a small variation to "move to to next<br>
indent" that stops at the end of the current intent rather than<br>
entering the next block and finding the first statement that has the<br>
same indent.<br>
<br>
Of course, a general implementation that works for many languages is<br>
going to be a lot more complicated than the Lisp one, which has the<br>
benefit of only having to match parentheses, but I feel like this is a<br>
very natural way way to move around code that might justify the<br>
implementation complexity.<br>
<br>
I'm also not volunteering to implement this, at least not the whole<br>
thing. I looked at the script API, and it would be doable there, but<br>
kind of hard because it's all character based and most of the semantic<br>
is not passed to the script. I think that the LSP Code Actions protocol<br>
would be the most logical way to do this since inside the LSP, there is<br>
a lot of semantic info available. It looks pretty heavy, however, so<br>
I'm not sure this is where a proof of concept should go. The external<br>
tools plugin however supports everything that is needed. If I can call<br>
a Python script, I can easily get the semeantic info back (for Python<br>
code). I would just need a way to pass back to Kate where to move the<br>
cursor as a response.<br>
<br>
Let me end with two unrealated questions:<br>
- does that sound like a way to move around code that you would like to<br>
use?<br>
- is there any chance that the external tools plugin would allow me to<br>
move the cursor in a nearby future?<br>
<br>
Sorry for the long message. I could not find a better way to summerize<br>
my thoughts.<br>
<br>
-- <br>
Yannick Gingras<br>
<a href="http://ygingras.net" rel="noreferrer noreferrer" target="_blank">http://ygingras.net</a><br>
<br>
</blockquote></div></div></div>