emacs minimap: how to highlight functions using semantic/face - python

I am trying to customize the minimap package in emacs.
I'd like to be able to read the name of the functions, class, etc while in the minimap. The effect I am trying to achieve is this (although in python mode): (from www.emacswiki.org/emacs/MiniMap)
As far as I understand the minimap module, there are two way to enlarge the name of function, class, etc.
The first requires semantic overlays, but I am not familiar with the semantic package, and I am not sure how well it supports python.
The second (that I set as the default option from M-x customize-group minimap) should use the normal text height for all the functions - all the text with the face font-lock-function-name-face - but I can't get it to work.
Does anyone know how to use this minimap function?

Related

Highlight initial variable assignment in python with VSCode

I would like to use tokenColor in Visual Studio Code to highlight the initial binding of a variable in python. That is to say, the first time a variable name appears in its scope, I would like it to have a different color. This would usually be where the keyword "let" or "var" would be used in JavaScript. How would I go about adding this to VSCode?
This is not possible using a simple language grammar as it requires understanding the structure of the program itself (i.e. understanding what are initial bindings vs re-assignments). This type of highlighting is called semantic highlighting.
As of VS Code 1.29, you can implement a custom version of semantic coloring using decorators. A proper semantic highlighting api is tracked by this issue

Python: How are objects/variables such as the complex '1j' defined?

And how can I define my own types of variables/objects to behave with the provided operations in python?
Can I do this without having to create my own object classes and operators as a separate and distinct entity? I dont mind having to create my own object class (thats a given), but I want it to integrate flawlessly with the already existing constructs. So emphasis on my wish to avoid "separate and distinct".
Im trying to create a quaternion object class. I want to define a 1i and 1k that are distinct from 1j.
And yes, a package might already exist; this is purely academic and for my own programming practice and understanding. Im trying to extend what is already there, and not build something that is distinct and separate.
I already do class objects but unfortunately they require a redefinition of the basic operations in order to make use of them, and even then I have to "declare" these objects before I can use them, quite unlike '1j'.
I hope I am clear with my intent. The end result of a quaternion is not my intent; it is the types of methods and objects and generalizations Im trying to figure out how to do, to extend and make use of what is already built into python.
It seems to me whoever built numpy and cmath have already been able to achieve this endeavor.
Thanks to the commentary below. I now have the vocabulary to express my intent better.
Im trying to add new features to Pythons SYNTAX.
If anyone can offer resources on how to do this, Id appreciate it.
I see two options for you here:
Change the Python syntax (fork CPython), there's a surprising amount of articles about how to do that.
Build some kind of preprocessor like Mypy.
Either way it seems like too much trouble just to have a new literal value.
Python does not support custom operators nor custom literals.
A language that supports custom literals is C++ (since C++11 I believe), but it does not support custom operators.
A language that supports custom operators is, for example, Haskell.
If you want to add this feature to Python you'll have to take the Python sources, modify its grammar, modify the lexer/parser and more importantly the compiler.
However at that point you just create a new language, which means you broke compatibility with python.
The easiest solution would simply be to write a simple preprocessor that replaces some simple syntax with an expanded equivalent. For example:
sed -i 's/(\d)+\+(\d+)i/MyComplex(\1, \2)/g' my_file.py
Then you can execute the preprocessor in the build step of your library/application.
This has the advantage of letting you write the code you want, but when you ship it/use it it is translated into normal python, keeping 100% compatibility with existing installations.
I believe using import hooks it would be possible to avoid having to ship the preprocessed version of your library... basically the preprocessor could be included in the import step and done on the fly. This would avoid having to deal with temporary preprocessed files.
The only requirement would be that people that need to use your library will have to install the import hook someway.

How do I display function arguments in ipython qtconsole?

I'm using IPython qtconsole under windows 7, and when I first write a method name and type the bracket, a popup shows method parameters.
What is the way to display that popup explicitly, once it has disappeared? This is pretty common 'show method parameters' shortcut that I'm talking about, but I've failed to find the shortcut to it after an embarrassing amount of google searches.
In Spyder, try View - Panes - Object inspector. Then type the full name of the function.
I would highly recommend relying on the Python Library Reference rather than any in-IDE tools, at least for functions and classes that are in the standard library. For objects outside those libraries however... it looks like you can type object_name followed by a question mark, that is, object_name?, to get a list of informative details about the object. (Since everything is an object, this presumably includes functions.)
For your specific question, it looks, from the iPython docs, like the TAB key is what you're looking for, but somehow I doubt you haven't already tried that.

Find where Python function is called in PyCharm

Is there a way for PyCharm to show where a given Python function is called from?
I currently rely on simply searching for the function name across the project and this often works fine, but if a function name is vague there are a lot of incorrect hits. I'm wondering if I'm missing a feature somewhere, e.g. perhaps the search results could be further narrowed down to only show where modules import the module I'm searching from?
In PyCharm you can select a function and press Alt+Shift+F7 to run a usage search. It's also available under "Edit → Find → Find Usages". It looks like it's more intelligent than a text search.
Using static analysis to find where a function is called from is difficult in general in Python because it uses dynamic binding and has a lot of introspection so it's very easy to get false positives miss usages. In the case of module-level functions I think a good solution is to always use module.function to call the function and never do a from module import function. That way you can do a text search for 'module.function'. Python style guides generally recommend that you import functions etc. in this way so I think this is generally accepted good practice.
Finding method calls is of course much harder. One of the things I like about developing in Java and C# is being able to find all usages of a method by static analysis.
Press the Ctrl key and simultaneously hover your mouse over the function header.The function name should get highlighted.Click on the function name to get a list of all instances where the function is called.
If you press the Ctrl key and simultaneously hover your mouse over a function call, then the function name will be highlighted and clicking on it will take you to the function definition.

What are the parameters for .GetWindow function in python?

I'm kinda new to programming, and I wanna write a simple program that needs to OCR a particular window. Currently, I'm using (w.GetForegroundWindow()), but that gets me the current window which would always be the Python shell, since that is the one that is active when I run it, even if it is for a split second only.
After searching around for a bit, I found the .Getwindows function, but not much of it on Python. What does it do, and what are the parameters? Will i be able to target a particular process (=window) with it? If not, what can I use then?
This is using the pywin32 module on Python 2.7 in Windows
I'm in Windows, Python 2.7 . The GetWindows function comes with the module pywin32, if im not wrong
The usual way is to call EnumWindows with a callback and then get information about each hwnd - for example name, title or window class. Check that against what you are looking for and save the matched hwnd. After EnumWindows returns, check that you found a valid hwnd and use that for your program.
It's not pleasant - there's not much support for this kind of thing in windows. I've heard that using accessibility features is better but I have no experience using that.

Categories