Komodo Edit: How to do some of these basic Macro and Snippet operations? - editor

I am wondering how to do (or where to find documentation) on these basic
macro and snippet operations in Komodo Edit.
1) FILE/IO: write a string to a temporary file from within a komodo javascript macro
2) FILE/IO: read the content of a text file into a string within a komodo javascript macro
3) INCLUDES: cross-reference local javascript "include" libraries within a macro,
or something equivalent to #script src="~/mylocal_javascript_addons.js" So I can consolidate macro code.
4) SNIPPET_OUTPUT: create a snippet interpolation placeholder that returns the output of a
user-defined javascript function or macro.
For example:
[[%(myscript:SayHelloWorld())]]
[[%(foomacro-MyAgeInMilliseconds)]]
5) MACRO_OUTPUT: macro that takes a multiple-line selection in the current buffer and passes
it to a local script or batch file, and then replaces the selection with the output
result. (Need a way to do this in MSFT Windows, not just linux).
If you can answer one or more of these using Python instead of Javascript, that's great, but please include sample code or a link to it, because the Python documentation seems to be extremely TODO.

Don't have your answers, but you might have more luck asking here:
http://community.activestate.com/forums/komodo-extensions

Related

Multiline command-line editing in Gforth console

I have just started learning the Forth programming language.
I'm using Gforth on Ubuntu. In Gforth interactive console, I want to do indentation but it requires changing line. Enter key didn't work, it executed code. For comparison, for example, when one tests JavaScript code in web browser console, shift+enter change line without executing code. I want something like that. What key should I press? Is there a way other than using text editors like vim?
Best.
Gforth doesn't support multiline editing (see the manual).
A workaround is to edit a file in your favorite editor in another window and reload this file in Gforth console as:
include /tmp/scratch.fs
An external file can be also edited in Gforth console via a command like:
"vim /tmp/scratch.fs" system
So a one-liner for that is:
"vim /tmp/scratch.fs" system "/tmp/scratch.fs" included
That can be wrapped into a definition as:
: scratch "vim /tmp/scratch.fs" system "/tmp/scratch.fs" included ;
So the word scratch will open an editor and than load the edited file.
NB: if you use a quite old build of Gforth, you have to use s" ccc" instead of "ccc" for string literals.
To conditionally include/exclude some parts in a file the words [defined] and [if] can be used; to erase the previous instance of the loaded definitions the word marker can be used as:
[defined] _clear [if] _clear [then]
marker _clear
\ some definitions
\ ...
Take into account that usual control-flow words can be used in definitions only.

What is the recommended way to make & load a library?

I want to make a small "library" to be used by my future maxima scripts, but I am not quite sure on how to proceed (I use wxMaxima). Maxima's documentation covers the save(), load() and loadFile() functions, yet does not provide examples. Therefore, I am not sure whether I am using the proper/best way or not. My current solution, which is based on this post, stores my library in the *.lisp format.
As a simple example, let's say that my library defines the cosSin(x) function. I open a new session and define this function as
(%i0) cosSin(x) := cos(x) * sin(x);
I then save it to a lisp file located in the /tmp/ directory.
(%i1) save("/tmp/lib.lisp");
I then open a new instance of maxima and load the library
(%i0) loadfile("/tmp/lib.lisp");
The cosSin(x) is now defined and can be called
(%i1) cosSin(%pi/4)
(%o1) 1/2
However, I noticed that a substantial number of the libraries shipped with maxima are of *.mac format: the /usr/share/maxima/5.37.2/share/ directory contains 428 *.mac files and 516 *.lisp files. Is it a better format? How would I generate such files?
More generally, what are the different ways a library can be saved and loaded? What is the recommended approach?
Usually people put the functions they need in a file name something.mac and then load("something.mac"); loads the functions into Maxima.
A file can contain any number of functions. A file can load other files, so if you have somethingA.mac and somethingB.mac, then you can have another file that just says load("somethingA.mac"); load("somethingB.mac");.
One can also create Lisp files and load them too, but it is not required to write functions in Lisp.
Unless you are specifically interested in writing Lisp functions, my advice is to write your functions in the Maxima language and put them in a file, using an ordinary text editor. Also, I recommend that you don't use save to save the functions to a file as Lisp code; just type the functions into a file, as Maxima code, with a plain text editor.
Take a look at the files in share to get a feeling for how other people have gone about it. I am looking right now at share/contrib/ggf.mac and I see it has a lengthy comment header describing its purpose -- such comments are always a good idea.
For principiants, like me,
Menu Edit:configure:Startup commands
Copy all the functions you have verified in the first box (this will write your wxmaxima-init.mac in the location indicated below)
Restart Wxmaxima.
Now you can access the functions whitout any load() command

Using signature file in script

I like using .fsi signature files to control visibility. However, if I have both Foo.fsi and Foo.fs files in my solution, and #load "Foo.fs" in a script, it doesn't seem like the corresponding signature file gets used. If I do:
#load "Foo.fsi"
#load "Foo.fs"
... then the desired visibility control happens. Is this the recommended way to achieve this, or is there a better way to do it? In a perfect world, one would like to see the signature file automatically loaded, too.
Not a final answer, but a better way.
From reading Expert F# 4.0 one can do
#load "Foo.fsi" "Foo.fs" "Foo.fsx"
All three loads are on one line.
TL;DR
The link to the book is via WolrdCat just put in a zip code and it will show you locations near there where the book can be found.

Creating macros using DWScript

I read this paragraph from the Delphi Tools Site
Changes since the last SVN update are:
Added support for FreePascal-like compile-time $INCLUDE “macros”:
%FILE% and %LINE% insert the current filename and line number into the source
%FUNCTION% inserts the current function name, or class.method name into the source
%DATE% and %TIME% allow inserting the compile date/time
Is there a way we can define macros in DWScript (other than these functions) just like people define macors in excel (using VBscript) in a simple way, where the name of the script will be the name of the function that will be used later, without adding {$Include XXX} in the executed script?
N.B.: I konw this can be done by managing the written script to be saved in a certain file called functions for ex. then save the added function with its name to be used (Add), then the user will write Add(1,2) to get the result; but my boss at work wants it to be something that looks like vbscript in excel.
I'm not sure to understand the question, so I'll list various answers to various possible interpretations...
If you want to declare functions that are implicitly supported by the scripting engine without having to "{$include}" or "uses" them, you can declare them via a TdwsUnit component, and attach it to the script component. If you don't have the "coExplicitUses" option set, they'll be available automatically, and you get design-time support in the IDE.
If you want to add internal functions (that are always there), use one of the RegisterInternalFunction overloads, you can check any of the "dwsXxxxFunctions.pas" units for examples. That's potentially more efficient, but also more cumbersome.
If you want to pre-process custom source-level macros in the source code (ala C's macros), you can use the filters functionality (check the HTML or JS filters as example of how a filter can be implemented).
If you want to react dynamically to "unknown" names, so you can declare them on the spot or bind them to something dynamically, you can use TdwsLanguageExtension.FindUnknownName, that's how the RTTI environment works f.i. (see TRTTIEnvironment in dwsRTTIConnector).
If you want to parse completely custom areas of code in a completely custom way, you can use language extensions too, override ReadInstr and check how asmLib & the JSLibModule do it to support "asm".

Generate code in C

I've got a library in C that I'd like to generate bindings for in Elisp. In Ruby, I'd simply include a header and then use its C API to generate functions and so on. Can I do the same on elisp? describe-function often says that a function is in "C source code". How are these generated?
Thanks!
You can check this Emacs doc to see how to wrap C function into a DEFUN macro to make it accessible from Emacs.
Once primitives are defined you need to recompile Emacs, you cannot load them dynamically in the runtime.

Resources