I put some functions' defination in a file named "funcs.red", functions in which would be invoked by main program. Here is the example of "funcs.red":
Red []
myadd: func [x y] [x + y]
The content of main program("main.red") is:
Red [needs: view]
do %funcs.red
view [t: text "result" button "myadd" [t/text: to-string myadd 1 2]]
Both "main.red" and "funcs.red" are in the same path.
In red console, the "main.red" works right as expected by do %funcs.red do %main.red. Then I tried to compile "main.red":
red -r -t windows main.red
but it failed and an error message was given:
Compilation Error: undefined word myadd...
So, in Red, how to link the main script with another script when compiling?
To reference other red sources at compile-time, you should use #include. When you use do, it looks for that file, reads and interprets it at run-time.
#include %funcs.red
You can still use #include when interpreting a script too. The interpreter will treat it the same as do in that case.
Related
I would like to configure VSCode in such a way that I can see red squiggly lines when there is an error in my python code.
My VSCode currently shows me Python syntax errors (e.g. pri nt("hello") will have a red squiggly line), but not the following errors:
class Dog:
attr1 = "mammal"
attr2 = "dog"
def fun(self):
print("I'm a", self.attr1)
print("I'm a", self.attr3)
Rodger = Dog()
print(Rodger.attr1)
Rodger.bark()
In the code above I would like to see a red squiggly line on print("I'm a", self.attr3) since this object doesn't have a self.attr3 attribute, and Rodger.bark() since this object doesn't have a bark method.
I think you might need to add python env path to your vscode.
Press ⌘ + ⇧ + P on the keyboard.
Screenshot
And then choose your python interpreter path.
(VS code will display available python interpreters.)
Then, vscode will detect the attributes itself.
Let me know if you have any questions.
I try to use a proper macro like .Bl with its .It to render list in mandoc (or per say man page) with the following syntax (as seen in mdoc.7)
The arguments are as follows:
.Bl -tag -width Ds
.It Fl v
Print verbose information.
.El
Tried both on macOS and Ubuntu 16.04 by putting into .SH DESCRIPTION, and it doesn't render expected output. All I see is
The arguments are as follows: Print verbose information.
The steps I do this is
Edit mandoc file
Symlink it to target file at /usr/local/share/man/man3/
See result by man <filename>
PS. I didn't go any gzip.
What did I miss? How can I properly render list in mandoc?
Instead, I look at mandoc's code of /usr/share/man/man1/bash.1 in which I view such man page via man /usr/share/man/man1/bash.1 for safety to ensure I view the right file.
It uses the following syntax
.TP 10
.BI Item Name
Item description
.TP
.BI Item Name 2
Item 2 description
This will properly renders those two items in which the first column has 10 character in width. The second item will use the same column width as defined before. Much cleaner and simpler than what I tried but with not success in the question.
You will see the following output using above syntax
When I open a cobol file in Notepad++ it looks normal. However, in Visual Studio Code it looks weird like it does not recognize the characters in it. How can I make it so that it looks normal in Visual Studio Code also.
Here is how it looks in both.
Notepad++
Visual Studio Code
It's probably saved in an encoding besides UTF-8. You can change the encoding with the "Change File Encoding" command, or by clicking on the encoding in the status bar. Or, try setting "files.autoGuessEncoding": true.
Put a call to the built-in input function
at the very bottom of the script in 3.X (in 2.X use the name raw_input instead). For example:
import sys # Load a library module
print(sys.platform)
input() # <== ADDED
input reads and returns the next line of standard input, waiting if there is none yet available. The net effect in this context will be to pause the script, thereby keeping the output window open until you press the Enter key
I am running a script which is fairly large. In the output screen I get ans = 10.
The problem is that the code is very large and I cannot pin point where this output is coming from.
Are there any tips to find the origin of this output within the MATLAB environment since I prefer not to have a random output on the screen?
In the case of a single script file, you can programmatically invoke mlint to return all warnings in the form of a struct:
L = mlint('my_filename'); % No need for .m at the end
Inspecting the structure you could see the following:
This structure has a field named 'message' which contains various issues, among which is what we're after - 'Terminate statement with semicolon to suppress output (in functions).'. At this stage you can run
find( strcmp({L.message},... % output is not suppressed on purpose
'Terminate statement with semicolon to suppress output (in functions).') )
Then inspect the line numbers that get printed.
Alternatively, if you want to skip the variable editor, or want to inspect a whole folder of .m files, you can run mlintrpt (in the case of a folder) or mlintrpt('plotWithoutOutliers') (in the case of a single file) and get a report in the following form:
As Luis said: look for the mlint error. In code this is shown as an orange shaded = and orange wiggle beneath it; on the scroll bar on the right it shows an orange line which you can hover over to see what the warning is and click on to go to the warning.
Additionally I included the red errors for completion. These will cause your code to be unable to run. Same here, red wiggle + red line on the right.
Last, the square on the top right, by the arrow, will either be green (no problems), orange (warnings, but the code will be able to run usually) or red (code won't be able to run).
Used Dev-iL's answer to create a simple function that will tell you the lines of code that are not suppressed. This way you don't need to inspect the returned lines in the structure L. Example: lines = UnsuppressedLines('isEven.m')
function [lines] = UnsuppressedLines( matlabScript)
l = mlint(matlabScript);
unsuppressedInstances = find( strcmp({l.message},'Terminate statement with semicolon to suppress output (in functions).') )
if isempty(unsuppressedInstances)
fprintf('No unsuppressed lines in script')
lines = [];
else
lines = {l.line};
lines = lines(unsuppressedInstances);
end
end
I would like to override double click in Sublime Text 3 to run my plugin code if and only if the user is in a certain view. Otherwise the double click should do the normal behavior (highlight the word and other instances in a file). However, I do not want the normal behavior to be run in my custom view.
The appropriate code for achieving this in Sublime Text 2 (and Python 2) can be found from https://www.sublimetext.com/forum/viewtopic.php?f=6&t=8823 but I am not able to refactor it to work in Sublime Text 3 (and Python 3).
The working code (taken from the aforementioned link) for Sublime Text 2 is:
class MySpecialDoubleclickCommand(sublime_plugin.TextCommand):
def run_(self, args):
if self.view.name() == "mySpecialBuffer":
self.doMyStuff()
else:
system_command = args["command"] if "command" in args else None
if system_command:
system_args = dict({"event": args["event"]}.items() + args["args"].items())
self.view.run_command(system_command, system_args)
In order to get it to work in Python 3 I refactored the dictionary handling code to (otherwise the code is the same):
system_args = dict({"event" : args["event"].items() | args["args"].items()})
However, when I call the run_command(system_command, system_args) method it returns the following error message:
File "C:\Program Files\Sublime Text 3\sublime.py", line 607, in run_command
sublime_api.view_run_command(self.view_id, cmd, args)
TypeError: Value required
Since the API documentation for Sublime Text 3 is almost nonexistent I am trying to figure out is there some problem in my system_args dictionary or is the API just changed in some other way?
Question is old, but better be late than sorry, stumble at it today
ValueError in my opinion is thrown by sublime.decode_value(string)
This method is decodes a JSON string into an object and as i think used in run_command then parsing args for running a command from keystroke or calling internaly.
The .sublime-keymap files contain a JSON array that contains JSON objects to specify the key bindings. The JSON objects must contain a keys and command key, and may also contain a args key if the command requires arguments.
So if arg value is not valid JSON object, you get ValueError
Workaround - pass strings or numbers
view.run_command('name', {'string_arg': 'string', 'num_arg': 1})
class NameCommand(sublime_plugin.TextCommand):
def run(self, edit, string_arg, num_arg):
pass
Or dump your object as JSON string pass to command and restore at place
Haven't done any mouse binding stuff myself, but it appears you are missing an argument for the run command. Note it expects 3 parms, you only give to. Have you tried passing in self.view.id as the first parm (based on the error, that's probably what it's expecting).