Pre-commit results in vim - vim

In Vim 8.1, I can run :!pre-commit run --files % to lint and auto-format the current file. Is there some way I can turn that (or any way of calling pre-commit) into in-editor highlighting, like https://github.com/dense-analysis/ale does?
In the past I've run ale in vim with pip-installed mypy, black, and yamllint and brew- or apt-installed shellcheck, delaying shell pre-commit runs until after editing. The downsides to that are in addition to the delayed feedback, this only brings a subset of the hooks into my editor (end-of-file-fixer is missing for example) and I haven't configured all of the twice-installed hooks as language: system, leaving the possibility open for in-editor and out-of-editor runs to diverge on versions and arguments. I could of course switch hooks over to language: system but I'm hoping for a way to go with the flow of using .pre-commit-config.yaml as the single-source-of-truth for versions and arguments, while surfacing results in-editor.

Related

nvim finds the function but vim does not

I am using a vim/nvim plugin asyncrun that enables an API call that works fine in nvim if I implement it in ~/.config/nvim/init.vim using a line:
call asyncrun#run("", "cwd", "firefox")
Now this same line does not work for vim if I try to use it inside ~/.vimrc. I always get a warning:
Unknown finction: asyncrun#run
What needs to be changed in order for this to also work for vim?
Following the #doopNudles comment I also clarify that vim plugin is manually installed in the folder ~/.vim/pack/my-plugins/start/vim-asyncrun/asyncrun.vim/plugin/asyncrun.vim. I install all my vim plugins the same way (using the vim v8 native ability to detect plugins).
The problem was that ~/.vim/pack/my-plugins/start/vim-asyncrun/asyncrun.vim/plugin/asyncrun.vim has one extra folder!
It works if I delete the extra folder asyncrun.vim like this ~/.vim/pack/my-plugins/start/vim-asyncrun/plugin/asyncrun.vim

Git bash, using VIM 8.1 on Windows :Term command. Node REPL not working correctly

I'm working on a corporate network (windows pc) with little access to tools like tmux, cmder etc.. however after recent update to git bash, we have access to Vim v8.1 which has a terminal built in.
I can load up vim and the type :term to load up a terminal... it works for standard terminal operations such as ls or git push etc.. but when you run node it seems to crash. And it doesn't render the node repl prompt.
Anyone know how I can get this working? (As predicted it works on the mac)... this is really useful to test out an algorithm quickly without leaving vim.
I also tried just typing !node to execute outside of vim and this has the same effect.
Any clues would be much appreciated.
Many thanks
Kevin
I figured it out...
You just type node -i for interactive (This isn't needed on the vim 8.1 on the mac)

Vim Latex Suite can't find latex command using Pathogen

Background
I was having dual boot issues with Windows 10 and Ubuntu 17.10, which eventually resulted in a boot loop and since I need Ubuntu 16.04.3 for an Operating Systems class I decided to load up an ISO into one of my USBs with Rufus, reformat my Windows partitions from GPT to NTFS to get around some nasty bootmg/efi issues and here we are, good as new, except for one thing...
Problem
The only thing I haven't been able to successfully reinstall has been Latex Suite for Vim. Installation last time had been an easy extraction into .vim, but after some deliberation I elected to use Pathogen.
I've installed Pathogen using
mkdir -p ~/.vim/autoload ~/.vim/bundle && \
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
Which works for color schemes, etc., and every other aspect of latex-suite save for compiling, generating this every time I try to compile (using \ll):
/bin/bash: latex: command not found
I installed texlive which does then allow me to compile using vim, but I'd prefer not to use this solution if I don't have to (in fact I've already removed it, its more of a plan b for now given it's obstructive and non-intuitive compilation errors). I looked at the other questions asking how to install Latex Suite through pathogen and didn't see anything else similar to what I'm working on; below is self-explanatory in regards to installation structure.
~/.vim/bundle$ ls
vim-archery vim-latex-1.10.0
Obvious running pdflatex and latex can't be found because they are not in my $PATH but I was under the impression that with a good, recommended package manager like Pathogen I wouldn't need to which is what originally raised the red flag for me as its whole job is to modify the runtime path. I thought maybe trying sudo vim text.tex might work in case there hadn't been adequate permissions for Pathogen to modify runtime path but no dice.
.vimrc
execute pathogen#infect()
syntax on
filetype plugin indent on
colorscheme archery
let g:tex_flavor='latex'
set sw=2

How to delete empty lines on visual studio code with the vim mode

I've been trying to delete many empty lines from a huge file. On other editors with vim, or vim itself, I could just do:
:%s/\n\n/\n/g
But neither if I use \r or \t it doesn't work. Seems like some vim features are missing on the editor. Is there any configuration to make that work or another way to do that?
To have advanced Vim functionality work within VScode, you can leverage its Neovim integration.
First, you'll have to install Neovim. For instructions, check out: https://github.com/neovim/neovim/wiki/Installing-Neovim
Then, adjust the following settings in your user configuration:
// Use neovim on backend. (only works for Ex commands right now). You should restart VScode after enable/disabling this for the changes to take effect. NOTE: Neovim must be installed (v0.2.0) and neovimPath must be set the executable in order for this setting to work. Otherwise, vscodevim will crash.
"vim.enableNeovim": true,
// Path to run neovim executable. For example, /usr/bin/nvim, or C:\Program Files\Neovim\bin\nvim.exe
"vim.neovimPath": "nvim",
Restart VScode. Now you can use Vim Ex commands, since the commands are sent to a headless Neovim instance that's running in the background. You can even use installed Vim plugin functions to a certain degree.

matlab script editing

I would like to edit matlab scripts in two cases
(1) In matlab Command window running in a linux terminal, how to create and edit a script file? use
edit(filename)
will invoke the interactive editor, which is not desired while operating on a linux server.
(2) In emacs, is there any way to edit matlab script conveniently? Which is better, using MATLAB-Emacs or EmacsLink?
when I am trying to cvs checkout MATLAB-Emacs from http://sourceforge.net/scm/?type=cvs&group_id=154105, which modulename should I specify?
Thanks!
EDIT:
When installing MATLAB-emacs, there is some problem. I thought my CEDET is installed here:
/usr/share/emacs22/site-lisp/cedet-common
/usr/share/emacs22/site-lisp/cedet-contrib
My CEDET is of version 1:1.0pre4-3 (intrepid) on Ubuntu. So I type the command:
$ make "LOADPATH=/usr/share/doc/cedet-common /usr/share/doc/cedet-contrib"
for loadpath in . /usr/share/doc/cedet-common /usr/share/doc/cedet-contrib; do \
echo "(add-to-list 'load-path \"$loadpath\")" >> autoloads-compile-script; \
done;
"emacs" -batch --no-site-file -l autoloads-compile-script -f cedet-batch-update-autoloads matlab-load.el .
Generatim autoloads for cedet-matlab.el...
Generatim autoloads for cedet-matlab.el...done
Generatim autoloads for matlab.el...
Generatim autoloads for matlab.el...done
Generatim autoloads for mlint.el...
Generatim autoloads for mlint.el...done
Generatim autoloads for semantic-matlab.el...
Generatim autoloads for semantic-matlab.el...done
Generatim autoloads for tlc.el...
Generatim autoloads for tlc.el...done
Generatim autoloads for semanticdb-matlab.el...
Generatim autoloads for semanticdb-matlab.el...done
Updatim header...
Updatim header...done
Wrote /home/tim/.emacs.d/matlab-emacs/matlab-load.el
make: *** No rule to make target `matlab-publish.el', needed by `lisp'. Stop.
What's wrong? Thanks!
You should be aware that starting with version R2009a EmacsLink has been removed from Matlab, so I would say that at this point Matlab-Emacs is a better alternative. The main strength of EmacsLink was tighter and integration with Matlab, especially when using the debugger, but current version of Matlab-Emacs is quite capable and will probably satisfy most people's needs just as well as EmacsLink.
In order to invoke Emacs from Matlab, the cleanest solution is to run the Emacs server (M-x server-start). The edit() command can then be set up to open the script in Emacs. The detailed instructions on how to do this, as well as on running matlab-shell as inferior process are provided here:
http://blogs.mathworks.com/desktop/2009/09/14/matlab-emacs-integration-is-back/
Regarding CVS checkout: modulename is "matlab-emacs". You used to be able to download an archive and simply unpack into your elisp directory.
EDIT: I decided to reinstall matlab-emacs; here is a step-by-step of what I did. (The steps are pretty obvious, but this might still be useful seeing how it's easy to run into a compilation error or to misinterpret some instructions). Note that matlab-emacs didn't compile until I reinstalled CEDET.
Download CEDET from http://cedet.sourceforge.net/ (1.0pre7 in my case)
Uncompress the archive into ~/.emacs.d/elisp/ (now have ~/.emacs.d/elisp/cedet-1.0pre7/ directory)
Compile CEDET via make EMACS=/usr/bin/emacs
While in ~/.emacs.d/elisp, do the cvs checkout:
cvs -z3 -d:pserver:anonymous#matlab-emacs.cvs.sourceforge.net:/cvsroot/matlab-emacs co -P matlab-emacs
Compile matlab-emacs via
make "LOADPATH=../cedet-1.0pre7/common ../cedet-1.0pre7/eieio ../cedet-1.0pre7/semantic/bovine/ ../cedet-1.0pre7/semantic/"
Ideally, everything should compile; now it's time to edit startup files: in the .emacs add
(setq load-path (cons "~/.emacs.d/elisp/matlab-emacs/" load-path))
(load-library "matlab-load")
and in matlab's startup.m add
addpath('~/.emacs.d/elisp/matlab-emacs/toolbox','-begin');
rehash;
emacsinit;
That should do it! Launch emacs, and do M-x matlab-shell. If edit foo.m doesn't open foo.m in emacs, make sure that the server has been launched (M-x server-start).
To be most productive, you might wish to figure out what works for you in terms of sending commands from the edit buffer to matlab process (experiment with the shortcuts in the mode help). Finally, if you need to debug stuff, do dbstop in foo, and when you run foo you can either use use dbstop family commands (look them up) or turn on toolbar (M-x tool-bar-mode) and use the buttons there to control breakpoints, stepping, continuing, etc. When finished, type dbquit.
Unfortunately, if you are on Windows, matlab-shell is not an option (which is a little surprising, seeing how I can run pretty much everything else under the sun from the command line -- Mathematica, R, numpy...) -- so your options for tight emacs/matlab integration are somewhat limited (unless you don't mind running an old matlab version that supports emacslink).
The matlab-emacs project at http://matlab-emacs.sourceforge.net/ is a slightly more up-to-date version of the Emacs scripts available in the EmacsLink directory that comes with MATLAB. It is OK to use the matlab-emacs project files with the EmacsLink files that comes with MATLAB.
The "modulename" is "matlab-emacs".
I made a blog post about how to use Emacs with MATLAB in more recent versions of MATLAB where the EmacsLink support was dropped. You can read it here:
http://blogs.mathworks.com/desktop/2009/09/14/matlab-emacs-integration-is-back/
The scripts here show how to tweak MATLAB to to use "emacsclient" so that files are pulled up in an already running Emacs.
EDIT:
The build system is a bit imperfect with a partial download. The fact that matlab-publish didn't compile is not critical.
The matlab-emacs code from CVS includes a toolbox directory with some M code in it. When you run that code, it should setup MATLAB to use emacsclient as the editor. I wrote emacsinit.m against the most recent MATLAB, so you may need to edit it with older MATLABs that don't support all features.
To run emacsclient from matlab-shell, the path should be setup automatically, and it should run emacsclient automatically. If you don't use matlab-shell, you will need to add that directory to your MATLAB path, then call emacsinit.
If it doesn't work for calls to edit, then I'd guess an older MATLAB doesn't have the same configuration features. You can start MATLAB once with the desktop enabled, and use the Preferences dialog to specify your external editor as emacsclient -n.
The reason that matlab-publish.el does not compile is because in fact it is not downloaded (thus missing) by the MATLAB script dl_emacs_support.m. I also find that the download script also did not download company-matlab-shell.el, which exists in the tarball from CVS. Consequently, when make is called, error occurs when the required files are not found.
Even worse, the dl_emacs_support.m script is replaced with the file from CVS when the source files are downloaded by executing the script in MATLAB. Patches or modifications to dl_emacs_support.m is thus lost after the files are downloaded.
To be safe, I recommend to download matlab-emacs from the tarball on the CVS server, or checkout the source. The compilation should go well then.
Remark about CEDET: I checked out CEDET source code and compile it with no sweat. If you are using Ubuntu, I believe the following packages in the repository should be installed before compiling matlab-emacs: cedet-common, ede, eieio, semantic, speedbar. These packages are installed to /usr/share/emacs/site-lisp, so the LOADPATH should be "/usr/share/emacs/site-lisp/cedet-common /usr/share/emacs/site-lisp/ede /usr/share/emacs/site-lisp/eieio /usr/share/emacs/site-lisp/semantic /usr/share/emacs/site-lisp/semantic/bovine".

Resources