Spacemacs: Run function after every file load - spacemacs

I have defined a function fira-code in dotspacemacs/user-init that runs the “setup” code for the Fira Code ligatures as described here: https://github.com/tonsky/FiraCode/wiki/Setting-up-Emacs
I then call this function in dotspacemacs/user-config. This almost works. When I first open a file, the ligatures are not shown, and Fira Code is not the current font. But if I then press <space> f e R to reload the config, it works. How can I make this work when first opening a file?

Instead of calling the function directly, add it as a prog-mode hook:
(add-hook 'prog-mode-hook
'fira-code)

Related

Testing with `use-ok` on modules with a `MAIN` definition

I am writing a new Perl 6 project for work, and would like to be able to test whether all parts can be used correctly. For this, I'm using the use-ok subroutine from the Test module. I'm trying to easily test all module files using the following code:
"META6.json".IO.slurp.&from-json<provides>
.grep(*.value.starts-with("lib")).Hash.keys
.map({ use-ok $_ })
My issue here is that there are a few files that contain a definition for a MAIN subroutine. From the output I see when running prove -e 'perl6 -Ilib' t, it looks like one of the files is having their MAIN executed, and then the testing stops.
I want to test whether these files can be used correctly, without actually running the MAIN subs that are defined within them. How would I do this?
The MAIN of a file is only executed if it is in the top level of the mainline of a program. So:
sub MAIN() is export { } # this will be executed when the mainline executes
However, if you move the MAIN sub out of the toplevel, it will not get executed. But you can still export it.
{
sub MAIN() is export { } # will *not* execute
}
Sorry for it taking so long to answer: it took a while for me to figure what the question was :-)

Change text by Command with VS-Code-Extension

I want to implement a second code formatting. This formatting should be executable by an additional command.
I have already registered a DocumentFormattingEditProvider and that is fine.
vscode.languages.registerDocumentFormattingEditProvider({ language: 'sosse' }, {
provideDocumentFormattingEdits(document: vscode.TextDocument) {
return formattingAction(document);
},
});
But in my case I need a second formatting action for one-liners, which is executed by an command.
I thought about using:
vscode.commands.registerCommand(command, callback)
But I don't know how to access and change the document.
But I don't know how to access and change the document.
There's a special variant of registerCommand() that I think is exactly what you're looking for: registerTextEditorCommand(). From the API docs:
Text editor commands are different from ordinary commands as they only execute when there is an active editor when the command is called. Also, the command handler of an editor command has access to the active editor and to an edit-builder.
That means the callback gets passed an instance of a TextEditor as well as a TextEditorEdit.

Visual Studio Code change my html code by itself and break all

Someone know the solution for this:
I have a simple Angular code inside Visual Studio Code and every time i save a file a fragment is changed by itself.
It: <app-mytag [myVarHere]="myVarHere"></app-mytag>
becomes it: <app-mytag></app-mytag>
by the simple act of save the file.
Im using nano editor outside to solve it.
Its my plugin list:
1tontech.angular-material
4tron.angular-material-snippets
Angular.ng-template
AngularDoc.angulardoc-vscode
EditorConfig.EditorConfig
GregorBiswanger.json2ts
HookyQR.beautify
MarinhoBrandao.Angular2Tests
NG-42.ng-fortytwo-vscode-extension
SimonTest.simontest
UVBrain.Angular2
abusaidm.html-snippets
anweber.vscode-tidyhtml
christian-kohler.npm-intellisense
christian-kohler.path-intellisense
dbaeumer.vscode-eslint
eg2.tslint
eg2.vscode-npm-script
esbenp.prettier-vscode
felixfbecker.php-debug
felixfbecker.php-intellisense
felixfbecker.php-pack
formulahendry.auto-close-tag
formulahendry.auto-rename-tag
jasonnutter.search-node-modules
johnpapa.Angular2
loiane.angular-extension-pack
ms-vscode.autorest
ms-vscode.cpptools
ms-vscode.typescript-javascript-grammar
msjsdiag.debugger-for-chrome
pkosta2006.rxjs-snippets
robertohuertasm.vscode-icons
steoates.autoimport
vuhrmeister.vscode-meteor
waderyan.nodejs-extension-pack
xabikos.JavaScriptSnippets
I think the culprit is anweber.vscode-tidyhtml plugin you are using. The reason why you lose the angular annotations is that, you have enabled tidyHtml.formatOnSave to true
You can disable the plugin or try removing tidyHtml.formatOnSave from your user settings by going in to:
Ctrl + F1 and type user settings
PS - I tried to recreate your problem and here's what happens:

Coldbox module event dying in renderLayout call

tl;dr: renderLayout(layout="myLayout", view="alpha/bravo/viewFile") resolves alpha as a module name rather than a package name in the host application, even if code execution is in the package rather than the module.
How do I get the path resolution to be consistent when either running the handler directly or when calling it via runEvent from a module?
I posted this on the CB google group, but then thought it may be best to ask here.
Working example here: https://github.com/jinglesthula/cbModuleExample
If you run install (I .gitignored the coldbox folder), then cd into the /app folder and server start --rewritesEnable you can visit http://127.0.0.1:<whatever port>/example/admin/test/ajax to see it in action.
From the example:
/app/modules_app/example/handlers/admin/test.cfc -> ajax() calls runEvent("admin.test.ajax")
/app/handlers/admin/test.cfc -> ajax() calls `renderLayout( layout = "layout.div", view = "admin/test/ajax" )
"admin/test/ajax" normally resolves to /app/views/admin/test/ajax.cfm, but in this case it's resolving to /app/modules_app/admin/views/test/ajax.cfm.
You can comment out line 18 and uncomment line 19 in /modules_app/example/admin/handlers/test.cfc to see a workaround.
You can also go to /admin/test/ajaxDirect in your browser to see that the renderLayout() call in the non-working example is correct.
Note: I have this.viewParentLookup = true in my ModuleConfig.cfc. I've tried reloading the module with it set to false and I get the same result.

Weird behavior of new figures in MATLAB

I have created a class-managed GUI in which the following methods are defined
function h = make_figure(this)
h = figure('CloseRequestFcn',#this.close_figure);
this.openFigures(end+1) = h;
end
function close_figure(this, src, event)
this.openFigures(this.openFigures == src) = [];
delete(src);
end
Throughout the life of the GUI maney figures are created and closed with the aid of the methods above. Now the weird part...
If I double click a figure file eg (myfigure.fig) in MATLAB's "Current Folder" window and then try to close it (while the GUI is still alive) then the close_figure method of the GUI's class runs although it wasn't created with h = figure('CloseRequestFcn',#this.close_figure); of make_figure method!!! This is the first weird part. The second weird part is that, although an unintented part of code is executed, it shouldn't create problems because the command this.openFigures(this.openFigures == src) = []; actually leaves this.openFigures unchanged and practically all that close_figure does is to delete(src) which is desirable. Despite the above, my program behaves... weird after the above happens.
I have noticed that if I hit figure in the command window and then close it, everything is OK, the close_figure method is not executed. The problem reveals itself only when opening a .fig file created by the GUI's class.
Any ideas?
I just tried the scenario you described, and I am not seeing any weird behavior; create instance of the class, use it to make a figure, then open a FIG file from the "Current Folder" file browser, and close it..
Here is the class definition I used:
classdef MyFigureClass < handle
properties
openFigures = [];
end
methods
function h = make_figure(obj)
h = figure('CloseRequestFcn',#(src,evt) close_figure(obj,src,evt));
obj.openFigures(end+1) = h;
end
function close_figure(obj, src, evt)
obj.openFigures(obj.openFigures == src) = [];
delete(src);
end
end
end
(Tested in R2012a on Windows XP 32-bit.)
EDIT
Ok I think I know what the problem is. Here are the step to reproduce. First add the following method to the class above:
function save_figure(obj, idx)
saveas(obj.openFigures(idx), sprintf('fig%02d.fig',idx))
end
Now using our class wrapper, lets create a figure, and save it to FIG file:
f = MyFigureClass();
f.make_figure()
f.save_figure(1) %# creates fig01.fig
Next clear your workspace clear all, and move the class definition file MyFigureClass.m to some other folder (something not on the path). Now try to load the saved figure hgload fig01.fig, and it will throw the error:
Warning: Cannot load an object of class 'MyFigureClass':
Its class cannot be found.
> In C:\Program Files\MATLAB\R2012a\toolbox\matlab\graphics\hgload.p>localLoadFile at 167
In C:\Program Files\MATLAB\R2012a\toolbox\matlab\graphics\hgload.p>hgload at 59
In openfig at 72
In open at 159
In uiopen at 196
You will have to issue the following command to forcefully close it:
close all force
EDIT2
One solution (as mentioned in the comments), is to reset the figure close callback function just before saving it. Here is how I modified the save_figure function above:
function save_figure(obj, idx)
%# backup callback function
fcn = get(obj.openFigures(idx),'CloseRequestFcn');
%# set default callback function
set(obj.openFigures(idx),'CloseRequestFcn','closereq')
%# save figure
saveas(obj.openFigures(idx), sprintf('fig%02d.fig',idx))
%# restore callback function
set(obj.openFigures(idx),'CloseRequestFcn',fcn)
end
I just wanted to point out that there is a related issue here that others may face. You should NOT open your GUI by double clicking the gui.fig file. This is not the desired behavior because your opening function will never be called. Should you have code in there as many of us do it will not execute, another side effect is that the handles variable will also not be set properly.
What you SHOULD do is either open it in GUIDE first then click run, or run the gui.m file directly. That will yield the desired results and the gui will function as intended.