How to specify color for function call in Emacs theme file? - emacs

In emacs, I want a function name get highlighted when it is called, not only defined or declared. I try to do this with a 'color-theme' theme file. But the theme file does not seem to have a variable to work this out, it has a variable 'font-lock-function-name-face', but this one only works for function declaration.
Is there some solution?
Thanks,
Utoah

There are a number of standard font lock faces, such as font-lock-comment-face, font-lock-function-name-face, font-lock-type-face, etc. It's up to each major mode to decide what is highlighted in each face. Programming language modes typically put comments in font-lock-comment-face, function names in definitions in font-lock-function-name-face, and so on. Some modes use font-lock-type-face only for definitions of type names while others use it for type annotations. There is no standard font lock face for function names in function calls, so most modes don't contain code to detect them. You'll probably have to modify the font locking code for the mode you're interested in.

Related

Visual Studio Code C++ color formatting in type declarations

As you can see, in C++ type declarations (string and new type), the colors of the types are in normal text color, which I find oddly peculiar, since it isn't the case for java source codes (even using the exact same theme).
I've tried customizing it in user settings:
But all that does is change the color of the type in the type definitions, not in the declarations.
I've also tried out various themes, but it's all the same.
Strangely, this doesn't happen for java source codes as shown in the image below:
I might be missing something. Maybe there's some field or attribute in the user settings that I should change instead of the 'type'.
Does anyone know how?
According to the Developer: Inpsect TM scopes command, the entire string x declaration has the same scopes:
source.cpp - the "base" scope for cpp files that everything in them has
meta.block.c - just tells you that it's inside of a block / {}
Consequently, there's not really anything to target with editor.tokenColorCustomizations, since that's based on scopes.
You could search for an extension that replaces the built-in CPP grammar with one that is better in this regard. Note that the only one I've found so far, Reloaded C/C++, doesn't help. Alternatively, you could search for a better grammar elsewhere - TmLanguage grammars are very commonplace and used in many editors, not just VSCode. Even GitHub uses them for their syntax highlighting.

Notepad++ and autocompletion

I'm using mainly Notepad++ for my C++ developing and recently i'm in need for some kind of basic autocompletion, nothing fuzzy, just want to type some letters and get my function declaration instead of having a manual opened all of the time..
The integrated autocompletion feature of my Notepad++ version (6.9.2) gives the declaration of basic C functionality like say fopen and parses my current file user defined functions, but without declaration.
I guess it's normal for a text editor to not give easily such information since it has nothing to parse i.e. other files where your declarations are (as it's not an IDE), but i don't want either to mess again with MSVC just for the sake of autocomplete.
Is there an easy, not so-hackish way to add some basic C++ and/or user defined autocomplete?
UPDATE
Adding declarations the "hard way" in some file cpp.xml is a no-no for me as i have a pretty big base of ever changing declarations. Is there a way to just input say some list of h/cpp files and get declarations? or this falls into custom plugin area ?
Edit the cpp.xml file and add all the keywords and function descriptions you'd like. Just make sure you add them in alphabetical order or they will not show up.
Another option is to select Function and word completion in the Auto-Completion area of the Settings-->Preferences dialog. NPP will suggest every "word" in the current file that starts with the first N letters you type (you choose a value for N in the Auto-Completion controls).

Confusing about the Emacs custom system

There are several similar setting functions:
set & setq
set-default
defcustom
custom-set-value
custom-set-variables
customize-set-value
customize-set-variable
so, what's the difference between these functions?
If I want setting my own preferences to an add-on, for these scenario:
If a variable setting by defcustom, which setting-function will be better?
And what about a variable setting by defvar?
The short answer to you question is:
use setq or setq-default for variables defined by defvar.
use setq, setq-default, or the Customize mechanism for variables defined by defcustom
Below is the long answer.
The functions that you are going to use are the following:
set is the main function to set the value of a variable.
setq is another version that automatically quotes its first argument. This is useful since quoting the first argument is what you want to do almost all the time.
Some variables cannot be set globally. Whenever you set the variable it is only set for the current buffer. If you want to simulate setting this variable globally you use set-default or setq-default.
The functions that a package writer uses are:
defvar which allows the package writer to define a variable and to give some documentation. This function is not required but makes the life of users easier.
defcustom builds on defvar. It tells emacs that it is a variable, and it allows the developer to create a custom interface to set the value. The developer can say, things like "this variable can contain only the value 'foo or 'bar".
Setting variables can be done two ways:
if defvar was used, the values can only be set by the user in its .emacs by using the set function (or variants)
if defcustom was used, the values can be set using set (see 1.) OR by using Customize. When using the customize mechanism, emacs will generate some code that it will place in custom-set-variables. The user should not use this function.
They are, largely all paths to the same thing. There are some important differences though. The best way to get to know them is to read the manuals for Emacs and Elisp (see C-h i). Off the top of the head though:
set is a "low-level" variable assignment
(setq foo bar) is shorthand for (set (quote foo) bar)
(set-default foo bar) means "unless there is a more explicitly scoped definition of foo in the current buffer, use the value bar", and applies to all buffers.
defcustom is used to mark a variable as one that the user is expected to be able to safely modify through the customize feature.
custom-set-value and customize-set-value are two names that point to the same function. They're convenience methods for working with the customize system.
custom-set-variables and customize-set-variables are used to make some set of customized-through-customize variables active, IIRC.
In general, it's recommended to use M-x customize to change things around. You're free to set things defined with defcustom using set or setq in your .emacs, the customize system will warn you about it if you later change it via customize though.
defcustom is generally only used by people writing packages meant for distribution, and I don't think I've seen anyone use custom-set-* outside of files internal to customize. setq is very common in people's initialization files for setting things up how they like them, regardless of whether those things are marked for use with customize or not.
I don't have a full understanding of all this, hopefully someone else can shed more light, but I think that that's a fairly good overview :P
set and setq are the lowest level primitives used for assigning any kind of variable.
set-default and setq-default are emacs extensions that go along with buffer-local variables, to allow setting the default values used for new buffers.
3-7. All the "custom" stuff is a later addition that was designed to support a user interface for managing variables that are intended to be used as user preferences.
defcustom is similar to defvar, but allows you to specify a place in the hierarchy of options, as well as data type information so that the UI can display the value as a menu, or automatically convert user input to the appropriate type.
I don't think there is a custom-set-value function.
custom-set-variables is used by the customize UI when saving all the user's options. It lists all the variables that the user has changed from their defaults.
6-7. custom-set-value and custom-set-variable are used by the Customize UI to prompt the user for the current and default values of an option variable, and assign them. You don't normally call this yourself.
Just as addition, the differences between those commands have increased due to the introduction of lexical binding, though those differences will not really be relevant if you just want to customize some variables.
The def... constructs declare global variables. The set... functions set variables, whether global or local. When x is neither a local variable (a formal parameter of the current function or declared by a let form or similiar) nor defined by a def... form and you write (setq x 0) the byte compiler will even show a warning
Warning: assignment to free variable `x'
Variables declared with defvar, defcustom, defconst are dynamically bound, i.e. when you have a construct
(let ((lisp-indent-offset 2))
(pp (some-function)))
the function some-function will see the change of the global variable lisp-indent-offset.
When a variable is not dynamically bound, in something like
(let ((my-local-var 1))
(some-function))
where my-local-var has no global value, then some-function will not see the assigned value, as it is lexically scoped.
On the other hand, dynamically scoped variables will not be captured into lexical closures.
More details can be seen in http://www.gnu.org/software/emacs/manual/html_node/elisp/Lexical-Binding.html

How are conflicting faces orders resolved?

(I don't know if the title of this question is correct)
When using several minor modes simultaneously changing 'colors', what determines in which order which modes shows what? For example I'm trying to use both highlight-changes-mode and rainbow-mode: http://julien.danjou.info/projects/emacs-packages
The problem I have is that when I enter a new color in my buffer (say #306090), instead of seeing the background color of the #306090 characters as rainbow-mode would want it to be, I see the background color (of the entire line) as changed (because I'm using highlight-changes-mode, which I like a lot).
My question is kinda a generic one: what determines in which "order" conflicts are resolved here? Does it depend on the loading order of the various modes?
It doesn't depend on the loading order of the modes. It depends on the respective mechanisms the modes use to apply the faces.
rainbow-mode uses font-lock to highlight text, which in turn uses so-called text properties. Text properties are intrinsic properties of string objects, and can belong to string objects that are not part of any buffer. (Text properties thus survive cutting and pasting, for example.)
highlight-changes-mode, in contrast, uses "overlays," which can be thought of as virtual text properties: An overlay is a specification of an interval in a buffer together with a specification of one or more properties that that interval should act as if it had; among the properties that an overlay can specify is a face. Overlay properties are not properties of the strings themselves (and so don't survive cutting and pasting).
If incompatible face attributes are specified by the text property of a buffer substring and an overlay covering that substring, then the overlay takes precedence. (If the face attributes aren't incompatible--as when a text property specifies a foreground color but no background color, and an overlay specifies merely a background color--then they're merged in the fashion you'd expect.)
In general the rules for merging faces are complex, because overlays themselves can specify strings to display at a buffer position, which strings in turn can have their own text properties, and different rules govern such cases; also, certain built-in faces like mouse highlights and mode-line faces are governed by their own rules. If you want to know more, see the info nodes "(elisp) Faces" and "(elisp) Overlays". For the complete story you'll need to look at the source code of the display routine (probably starting with handle_face_prop in xdisp.c and face_at_string_position in xfaces.c).

Code chunk fontification in Emacs noweb mode?

In noweb mode, I would like to make the doc chunks and code chunks easier to distinguish. I'm already using font-lock-mode, but it applies the same face to strings in R and strings in tex, so doesn't distinguish the code and doc chunks very well.
For example, a slightly different background color for the code chunks.
One possibility would be to define a new face for the minor mode of the code chunk, but then that face would also apply when editing a buffer in that mode.
Another possibility would be to create an overlay for the code chunks.
Also, somewhat related, org-mode can be configured to use different background colors for source blocks.
Update: I now use polymode to achive this.
You can use noweb-font-lock-mode from ESS to get syntax highlighting for both code and documentation chunks. I'd recommend you also use noweb-mode from ESS too, because it has some improvements.
One option would be mmm-mode, with which you can define regions that are in a different mode -- it also applies a face to the entire sub-mode region, which you can use to easily distinguish those regions within the parent file.
I personally use this for Ruby within IRB, Javascript and CSS within HTML etc. There's an example for javascript in my emacs config.
The MuMaMo extensions allows different rules for different parts of the file. Getting the nXhtml package will give you the mode and I think you can configure it to do what you want.