Adding a new Scintilla Lexer to Geany - lexer

I wrote a new lexer for a custom Language in Scintilla. I followed both scintilla and geany documentation along with hacking geany.
However geany does not recognize my language. I also implement filetype for it but still it does not seem among Document->Set Filetypes.
To be more precise assume you have such a lexer . What must be procedure to follow for finding this language among Document->Set Filetypes.

Related

Possibility to read .xtend on Geany text editor

Context: I would like to read file .xtend. Normally I use Geany as a text editor.
Questions:
Is it possible reading file .xtend on Geany? What I mean is that the language is recognized and the keywords highlighted.
If so, how to make it possible? Any procedure?
According to Wikipedia, Xtend is syntactically similar to Java. Try opening an Xtend file in Geany, setting the highlighting to Java by selecting Document > Set Filetype > Programming Languages > Java source code, and see if that serves the purpose. If it does, you can then create a custom filetype for .xtend files by copying the Java filetype and adding the appropriate configuration info as noted in the Geany manual.

Let Vim interpret and highlight code comments/docs as markdown [duplicate]

The newer version of doxygen comes with markdown support. Is there an easy way to add markdown syntax highlight to a doxygen comment block in vim?
On a side note, one can add doxygen syntax to a c file by using set filetype=c.doxygen
To do this right, the Doxygen syntax extension script would need to be extended to support Markdown syntax, either by duplicating the syntax, or by defining regions that can include Markdown and using :syntax include syntax/markdown.vim to include the syntax. Please contact the syntax plugin's owner with such a request, or even send a patch.
For a pragmatic approach that you can immediately use, my SyntaxRange plugin provides a command that can highlight certain ranges with a different syntax:
:3,11SyntaxInclude markdown
With this (possibly aided by a custom mapping to make this faster), you can highlight Doxygen-Markdown ranges on demand (e.g. when the text markup is so complex that you would have the comfort of proper syntax highlighting).

How can I hightlight markdown in doxygen under vim?

The newer version of doxygen comes with markdown support. Is there an easy way to add markdown syntax highlight to a doxygen comment block in vim?
On a side note, one can add doxygen syntax to a c file by using set filetype=c.doxygen
To do this right, the Doxygen syntax extension script would need to be extended to support Markdown syntax, either by duplicating the syntax, or by defining regions that can include Markdown and using :syntax include syntax/markdown.vim to include the syntax. Please contact the syntax plugin's owner with such a request, or even send a patch.
For a pragmatic approach that you can immediately use, my SyntaxRange plugin provides a command that can highlight certain ranges with a different syntax:
:3,11SyntaxInclude markdown
With this (possibly aided by a custom mapping to make this faster), you can highlight Doxygen-Markdown ranges on demand (e.g. when the text markup is so complex that you would have the comfort of proper syntax highlighting).

Prolog support for Vim users

I am starting with Prolog programming using XSB.
What syntax highlighting script or plugin for vim editor would you suggest for (XSB) Prolog ?
Vim (7.3) comes with filetype-specific settings and syntax highlighting for Prolog. Just make sure that your file is detected as such (i.e. :setlocal filetype? prints prolog), and you have the usual :filetype plugin on and :syntax on in your ~/.vimrc.
Vim auto-detects *.pdb and *.pl (depending on contents, can also be Perl); but you can configure additional patterns, see :help new-filetype.
The Vim support for Logtalk is an alternative for syntax coloring of Prolog files. Given that Logtalk extends Prolog, you will get nice syntax coloring for official and de facto standard Prolog features. The latest version is available here:
https://github.com/LogtalkDotOrg/logtalk3/tree/master/coding/vim
You will need to configure Vim, however, to use the Logtalk syntax highlighter support for the Prolog files (basically to recognize the file extensions that you're using for Prolog; e.g. XSB, by default, prefers .P). Also do try different Vim themes. Some of them are more pleasant than others.
There are two big plugins "set" for working with Prolog in Vim:
adimit/prolog.vim - widely known but abandoned
soli/prolog-vim - lesser known, but more updated and advanced
You can check files of the second - they are extending standard prolog.vim which comes with Vim, but including it. Moreover they support different flavours of Prolog - SWI Prolog, GNU Prolog, etc. You can use them as an examble and create your own.

Refactoring in Vim

Of course the fact that you can refactor on IDEs is priceless for many, I hardly ever do it when I am coding but I may try to do it when editing some one else's source. How do you accomplish such a trivial task across multiple files in Vim?
I found this plugin for refactoring Ruby, but how about "any" language?
I agree with the 'Vim is not an IDE' paradigm. But there are times when there isn't an IDE. Here's what I use in those situations:
Disclaimer: The ubiquity of Language Server Protocol servers, linters and fixers since I wrote this have also brought some great refactoring capabilities to Vim (and other editors). IMO they are a long way from equaling the capabilities of a purpose-built IDE (I prefer ALE and nvim-lspconfig for these kinds of features). See other answers on this question for more info!
:grep, :vimgrep, :GrepperAg, :Ggrep
Refactoring that has more to do with regular replacements I usually use :grep on my project tree and then record a macro to do the refactor - :g and :s are no brainers. Usually it'll let me quickly modify a large number of files with very little effort. Honestly, I use this method more than any other.
Depending on your workflow the built-in commands might be slow/inconvenient. If you use git, then you'll wanna use the excellent Fugitive plugin and its :Ggrep command to only search files checked into git. I also like the vim-grepper because it is search-tool-agnostic (supports ag, sift, ripgrep, etc) and speedy.
:argdo, :cdo, and :bufdo
:cdo and :argdo are handy to execute vim commands over a set of files.
command line
When it's harder to determine the list of files that need changes via :vimgrep I resort to the command line grep/find commands to more closely curate the list of files that I need to refactor. Save the list to a text file and use :e and a mashup of macro recordings to make the changes I need to make.
I find that the less rusty I keep my macro recording skills the more useful I find Vim for refactoring: feeling comfortable saving/restoring from registers, incrementing/decrementing register counter variables, cleaning/saving macro recordings to file for later use, etc.
Update
Since writing this more videocasts for the methods I describe have been published on vimcasts.org (I encourage you to watch ALL the Vimcasts!). For refactoring watch these ones:
Substitution with :Subvert
Project wide search/replace
Search multiple files with :vimgrep
Use :argdo to change multiple files
Vimgolf is also a great way to practice.
Language Server Protocol (LSP)
The Language server protocol contains the feature for smart renaming of symbols across a project:
https://microsoft.github.io//language-server-protocol/specifications/specification-3-14/#textDocument_rename
For example following language server support this:
Clangd for C++
ccls for C/C++/Objective-C
Eclipse.jdt.ls for Java
pyls (with rope) for Python
tsserver for TypeScript
Solargraph for Ruby
gopls official lsp for Go (alpha stage in Nov 2019)
texlab for LaTeX
You can find more language servers under https://langserver.org/.
Vim
A vim editor client is necessary to use them within vim. Following options exist:
LanguageClient-neovim (requires rust) suggests the mapping:
nnoremap <silent> <F2> :call LanguageClient_textDocument_rename()<CR>
coc.nvim (requires node.js) suggests the mapping:
" Remap for rename current word
nmap <leader>rn <Plug>(coc-rename)
Ale has
nnoremap <silent> <Plug>(ale_rename) :ALERename<Return>
Ale does not define any keybindings. This has to be done by the user.
vim-lsp provides following command
:LspRename
Similar to Ale no mapping is suggested. However, of course you can define one as following
nmap <leader>r <plug>(lsp-rename)
(<leader>r is to be replaced by your choice; I do not know one which most plugins agree on)
vim-lsc has a default mapping:
'Rename': 'gR'
See also YouCompleteMe which facilitates LSPs as well.
Neovim
Neovim has initial builtin support for lsp since 13.11.2019
See for common configurations of LSPs the project nvim-lspconfig which suggests <space>rn as a mapping for vim.lsp.buf.rename().
Other Refactorings
I do not know if there are plans for the LSP protocol to support more complex refactorings, such as changing class structure, adding parameters to methods/functions or moving a method to a different class. For a list of refactorings see https://refactoring.com/catalog/.
Python
For the python language following plugins provide 'smart' renaming capabilities for vim:
jedi-vim (github) <leader>r
ropevim (github) CTRL-c r r
python-mode (github) :h pymode-rope-refactoring
C-Family
Try the plugin Clighter for rename-refactoring for the c-family. It is based on clang, but there are limitations and the plugin is marked as deprecated.
Suggested mapping by Clighter is
nmap <silent> <Leader>r :call clighter#Rename()<CR>
Note, the successor plugin clighter8 has removed the renaming functionality in the commit 24927db42.
If you use neovim, you can take a look at the plugin clamp. It suggests
nmap <silent> <Leader>r :call ClampRename()<CR>
Maybe not the most elegant solution, but I found it very handy: I use ECLIM to connect VIM and Eclipse. Of course all my source code editing is done in VIM, but when it's time to refactor, one can take advantage of Eclipse's superior cababilities in this matter.
Give it a try.
I wrote this plugin for generic refactoring. It still requires many improvements. Sometime in the future I'll try to abandon ctags in favour of clang for C&C++ refactorings.
Plugin YouCompleteMe (YCM) (20k stars on github)
http://ycm-core.github.io/YouCompleteMe/#the-refactorrename-new-name-subcommand
:h RefactorRename-new-name
In supported file types, this command attempts to perform a semantic
rename of the identifier under the cursor. This includes renaming
declarations, definitions and usages of the identifier, or any other
language-appropriate action. The specific behavior is defined by the
semantic engine in use.
Similar to FixIt, this command applies automatic modifications to your
source files. Rename operations may involve changes to multiple files,
which may or may not be open in Vim buffers at the time. YouCompleteMe
handles all of this for you. The behavior is described in the
following section.
Supported in filetypes: c, cpp, objc, objcpp, cuda, java, javascript,
typescript, rust, cs
By default there is no mapping.
Plugin Factorus
There is another vim plugin dedicated for refactoring called factorus which is available on github.
Currently (2017-12), it supports the languages
c,
java, and
python.
Place cursor at name to refactor and type
gd (or gD if you're refactoring a global variable).
Then
cgn new_name esc
and
. one or more times to refactor next occurrence(s)
or
:%norm . to refactor all occurrences in the buffer at once.
I write a lot of C/C++ code in vim. The most common refactoring that I do is renaming variables, class names, etc. Usually, I use :bufdo :%s/source/dest/g to do a search/replace in files, which is almost the same as renaming provided by big IDE's.
However, in my case, I found that I usually rename similar entities, spelled in different cases (i.e CamelCase, snake_case, etc.), so I decided to write a small utility to help with this kind of "smart-case" search/replace, it is hosted here. It is a command-line utility, not a plugin for vim, I hope that you can find it useful.
Go
The tool godoctor (github) supports several refactoring capabilities
Rename
Extract Function
Extract Local Variable
Toggle var ⇔ :=
Add Godoc stubs
There is a vim plugin https://github.com/godoctor/godoctor.vim which makes them available
With cursor in thing to rename:
:Rename <newname>
Highlighting block to extract:
:Refactor extract newfunc
vim-go
Precise type-safe renaming of identifiers with :GoRename.
Language server gopls
https://github.com/golang/tools/blob/master/gopls/doc/status.md#rename
For refactoring, if you're using Unite (and you should), you can then use vim-qfreplace and make it extremely easy. Check this video that demonstrates how it works. Once your workflow is set, you can make some mappings to optimize it (instead of typing most things like in the video).
A combination of two plugins: vim-ripgrep, to find across files and put the results in the quickfix window, and quickfix-reflector to save the changes right in the quickfix window and have it automatically save each change across the files.
I would consider using the spacemacs version of emacs. It is uses the same modes and most keystrokes as Vim but has many more add-on because of it's lisp nature. If you want to program in C++ you just add the c++ layer and most of the IDE is just set up for you already. For other interpreted languages like python or bash you do not need to leave spacemacs to use them. They even have a way to run blocks of code directly within your text which works fantastic for literate programming or reproducible programming where the code and the data are in the same file. Both done as text.
Spacemacs is much more heavy handed in it's initial load but the additional stuff you can do with it is worth the few seconds of startup cost. One layer org-mode is worth checking it out. It is the best outliner, programmer, day timer / todo list I have ever used.
The CoC addon has (among other features) the ability to rename variables.
https://github.com/neoclide/coc.nvim
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)

Resources