Custom syntax highlighting in Geany - syntax-highlighting

I am trying to create custom syntax highlighting for Kivy '.kv' files in the Geany editor. Although the specific filetype seems irrelavant to the issue I'm having, as any efforts I make at getting syntax highlighting to work for a custom filetype results in a completely non-highlighted file. I believe I have done my homework on this, and nothing seems to work.
I have added the following to ~/.config/geany/filetype_extensions.conf
Kivy=*.kv;
I also have a custom type definition file named 'filetypes.Kivy.conf' in ~/.config/geany/filedefs/. I have tried basing this file off several of the stock type definition files in /usr/share/geany/ and the file never gets any syntax highlighting applied in Geany. Right now, just for experimentation's sake, my 'filetypes.Kivy.conf' file looks like this:
# For complete documentation of this file, please see Geany's main documentation
[settings]
# default extension used when saving files
extension=kv
# single comments, like # in this file
comment_single=#
[keywords]
# all items must be in one line
primary=size canvas
secondary=pos size
[indentation]
width=4
# 0 is spaces, 1 is tabs, 2 is tab & spaces
type=0
This is very loosly based on the stock XML definition file, but like I said I've tried many other stock files. In many cases I only changed the 'extension=' value to kv and still no highlighting was applied, even though going to Document>Set Filetype in Geany and choosing virtually any random filetype (besides my custom entry) would yeild some sort of highlighting within my .kv file. This is even the case when using the unmodified contents of a stock definition which otherwise works fine on my .kv file when specifically selected in Geany!
Also, the Kivy filetype is listed and selected by default in Document>Set Filetype within Geany, so I must be doing something right here!
I realize this similar question has been asked, but the solutions seem irrelavent to my case, as I've tried every related topic on this and many other sites. My Geany version is 1.22 and I'm running Arch Linux. This is driving me nuts - any suggestions?
Thank you!

Set lexer_filetype= property in the [settings] section of your filetype file. Working highlighting requires that there is a lexer that could be used for highlighting the .kv-files.
For more info see http://www.geany.org/manual/#lexer-filetype

There are three important things to obey:
the configuration file should be placed in "~/.config/geany/filedefs"
the configuration file must have the extension ".conf" - otherwise it won't show up at all (the files in "/usr/share/geany/filesdefs", where I copied my base file from, do not have a ".conf" extension!)
you must set the "lexer_filetype" to an existing (presumably builtin) configuration; e.g. "lexer_filetype=Python"

Related

VS Code - Ruby code completion with attributes from other Ruby files

I have an issue, I wouldn't say it's a problem at the moment, but I can see how it could turn into one in the future.
I'm following some tutorials from Ruby, so I have a folder with a bunch of different files. In one of them, I was studying Hashes, and they showed that I could name its keys like :key. No problem so far.
The issue came when I was studying Classes and I had to declare the class attributes, IntelliSense (I guess, maybe it is another extension) would recommend code completion with the keys I declared in that Hashes ruby file.
So I tested some stuff and:
It wasn't unique to that file (of course).
It's not just in hashes, it will recommend any type of :attribute I create. Whether it is classes or hashes (which is what I have tried so far), it doesn't matter.
It isn't unique to that folder. If I have the files in different folders, with different depths let's say, it will still appear.
The only way I found to get rid of that was to erase the file, and that's no solution at all.
I guess my precise question is: How can I disable that code completion characteristic?
You can ignore file or folder in code completion by adding it to files.watcherExclude setting.
Files must be closed in editor: if ignored file is open, it will still be used for autocomplete.

A new language, how to auto-complete in windows vim?

I'm using Gvim in windows.
Normally, when we type some character then press Ctrl-n, vim will show some tag, but those tags just includes words which have been pre-typed in the current file.
Now, I need it working in a new language, and show the tag which has been defined in other files.
So, I create a new \\.ctags for this new language, and generate tags file by exuberant-ctags.
I can choose a function in current file, then press Ctrl-] to jump to the function definition, but this function was define in the other files. It is working very well.
I don't know how to make it show the tags which are generated by ctags when I type some character.
Please help me. Thanks very much.
My English is poor, I hope you can understand what I said.
CTRL-N is just the default completion (which completes from a variety of sources, including the open buffers and also the tags database). There are many more specialized completions (all starting with CTRL-X), among them tags completion, triggered via CTRL-X CTRL-], see :help i_CTRL-X_CTRL-]. If you've correctly configured the 'tags' option (so your tags database is found) and tags jumps do work, just start using that.
Some languages / filetypes also define a language-specific completion (for language keywords etc.), usually via the 'omnifunc' option and triggered by CTRL-X CTRL-O. You could write such yourself, too.

What is the option that makes Sublime Text add whitespace at the left of wrapped lines?

I want Sublime to treat my text files like they are source code files and show whitespace at the left of wrapped lines, like so:
beginning of long line blah blah blah, now it wraps
and it keeps going after an automatic indent
I tried opening the console and setting the option manually:
view.settings().set('indent_subsequent_lines', True)
but nothing changes, any ideas?
Well, that was fun. There's no easily accessible setting for this. But as you indicate, ST decides whether to add an extra indent when soft wrapping, from whether the syntax is considered code-like or plain text-like.
Being one or the other is up to the package defining the syntax to specify. So lacking a global setting from ST, you need to change your text packages. As an example, let's take Text. That contains Plain text.tmLanguage. In that you change
<key>scopeName</key>
<string>text.plain</string>
to
<key>scopeName</key>
<string>source.plain</string>
I'm unsure of whether there'll be ill effects from not keeping .plain.
One easy way to do this is to get the PackageResourceViewerpackage.
After install, do:
cmdshiftp
Type: Open Resource
return
Type: Text
return
Type: Plain text.tmLanguage
Make your edit and save.
PackageResourceViewer will save the modified Text package to your Packages directory. And sublime will display files considered to have Plain text-syntax, like they are code.
The caveat is that you need to do this for every text-syntax you want to be considered code.
As #AdamAL said, it's dependent on both the 'indent_subsequent_lines' setting as well as whether it's considered a "source" or a "text" language ... by default, "markup" languages (such as HTML, CSS, etc.) and plain text, etc., are considered "text", and programming languages such as C++, Java, PHP, etc., are considered "source".
"Source" languages will indent subsequent soft-wrapped lines (if the indent_subsequent_lines is true), whereas "text" languages will only indent up to the same level as the current line.
For each one you want to change, you'll need to edit the settings of the given language. #AdamAL's answer provides a great way to do this using the PackageResourceViewer package:
After install, do:
[Ctrl/Cmd]+[shift]+p, "Open Resource"
Find the name of the language you want to change, and find either the .sublime-syntax file or the .tmLanguage file. .sublime-syntax is supported from build 3084 of ST 3 and appears that it may trump values in the .tmLanguage file in supported versions, if present (when editing the definition of TaskPaper files provided by the "PlainTasks" package, my change didn't take when just editing the PlainTasks.tmLanguage, I had to edit the PlainTasks.sublime-syntax before it took).
In .sublime-syntax (which are YAML files) look for the first scope: line, where the main scope name of the language is identified (there will be lots of other scope: entries further down under contexts:).
In .tmLanguage (which are XML .plist files) look for the <string> following the <key>scopeName</key>.
Sublime Text Syntax Definition Documentation Reference:
scopeName
Name of the topmost scope for this syntax definition. Either source.<lang> or text.<lang>. Use source for programming languages and text for markup and everything else.
The <lang> (without brackets) is just an identifier string for the given syntax/language definition.
I noted that it seems that (in ST 3, anyway), no restart of Sublime Text is needed to get the changes to apply, if the edit is in the right place.
And also note that there may be other effects of changing this in more complex packages -- For example, in PlainTasks, the additional keybindings that it defines depended on it looking for a context that included text.todo, which I changed to source.todo in several places. So in order for the keybindings to work properly again, I also had to update my .sublime-keymap for that package. (This could also be because I changed it in a place besides the .sublime-syntax that I didn't need to. Just sayin' -- YMMV.)

How to create this sublime text syntax?

I am trying to create a simple sublime syntax where when the first word of a line is "DONE" the whole line turns to a different color.
For example:
- do this
DONE - do that // this line turns green
- but also do this
My two questions are:
- How does one go about creating a ST syntax
- How would I create the above simple syntax.
The most you could highlight is the region containing text. I don't know if that's what you are looking for. To do this would require defining a tmLanguage file and modifying you tmTheme file. The tmLanguage file describes a set of regular expressions for which a scope is applied to the text within ST. The tmTheme file takes the scopes applied, and applies some coloring. I'm not an expert on writing either of these files, so you may need to do some experimentation on your own.
For information on writing syntax files, see here and here. The theme files are much simpler, in terms of defining them. Those guides recommend using AAAPackageDev, which is not necessary (and not compatible with ST3 last I checked). The language files are all XML, which you can work with, but I find working in JSON or YAML easier. If you feel the same way, you can start with the below snippet and use SerializedDataConverter to convert between XML and PLIST/JSON.
{
"name": "Syntax Name",
"scopeName": "source.syntax_name",
"fileTypes": [""],
"patterns": [
],
"uuid": "ca03e751-04ef-4330-9a6b-9b99aae1c418"
}
I can't recall the location of any references, but I'm sure they're out there. Though, simply viewing some existing theme files may be enough for you. TO view these, you can use PackageResourceViewer. Isn't really necessary if you are working in ST2, but makes things much easier in ST3. To begin working on your own custom theme, I'd copy the contents of the theme file you are currently to a new file, and save it in your Packages/User directory. That way, you always have something to revert to, in case you mess something up.

VIM: created syntax not showing up?

HI people
I recently changed to VIM for coding in C.
I'd like to hightlight the operators +-<=& ... etc
I searched in google how should i do it, and i found the answer in this website: I was suppose to do something like:
syntax match Operadores /[][><()&!|+*={}-]/
hi Operadores guifg=#000000 gui=BOLD
Those characters were supposed to appear as black, bold characters.
However, that doesn't happen when I open my .C files. However, if I create a newfile, (where there the C syntax doesn't show up), I am able to see the black, bolded operators.
How can i correct this situation, and why is this happening (it seams like if my syntax is beeing overwrided by the C syntax).
I'm using gvim, and this is my vimrc:
colorscheme nicotine
set smartindent
set number
set guifont=Inconsolata\ Medium\ 11
set numberwidth=5
noremap j jzz
noremap k kzz
Thanks, any help is appreciated.
(And dont forget I'm a novice in VIM, and ..sorry for my English)
The best way to do this is putting those two lines in the following file:
~/.vim/ftplugin/c.vim
creating it if it's not already present (of course you need to adjust the path to your personal Vim directory if you're not on un*x). That file is called for every C file you edit, and it's executed after the default scripts so your syntax won't be overridden.
For ftplugin to work you also have to add
filetype on
although a full
filetype plugin indent on
is usually more generally useful.

Resources