how to tangle source code blocks that belong to a specific target file? - emacs

I have many source code blocks interleaved around in my org-mode file. They can be tangled to 3 different files as specified in the header args of each block. My question is: instead of tangle all of the 3 files, what elisp code I can use to tangle the blocks that belong to a single given target file?

To tangle the source code blocks that belong to a specific target file, you can use the "org-babel-tangle-file" function in elisp. This function takes the name of the org-mode file and the target file as arguments, and tangles all of the source code blocks in the org-mode file that have the specified target file in their header arguments.
For example, if your org-mode file is named "myfile.org" and you want to tangle the source code blocks that belong to the target file "target1.py", you can use the following elisp code:
(org-babel-tangle-file "myfile.org" "target1.py")
This will tangle all of the source code blocks in "myfile.org" that have "target1.py" as their target file, and save the tangled code to "target1.py". You can then use the same function to tangle the source code blocks that belong to other target files, by specifying the appropriate target file name as the second argument.

Related

What is the convention for Racket filename extensions?

.rkt is the conventional file extension for 'regular' Racket source code. In the documentation, I also see .rktl and .rkts being used. What are .rktl and .rkts used for, and are there any more Racket filename extensions I am not aware of?
The .rkt file extension is generally used for files that represent modules. These normally have a #lang .... line at the top, or sometimes (module ....). They can be imported as modules with require.
The .rktl and .rkts file extensions are used for files meant to be loaded at the top-level that aren't modules. They don't necessarily have a #lang .... line at the top, and must be loaded in some external environment with load instead of imported with require. These usually have a more "dynamic" feel to them, and they're used more often with scripts that use mutation of variables across multiple files. This is not the "encouraged" style in Racket.
The .rktd file extension is used for files that just have data encoded as s-expressions, not code. These files should not be required or loaded (they should not be executed as code). However, other programs use them to store data on the file system using write, and to read the data later using read. Its purpose is the same as a .sexp file or a .json file, just pure data.

Multiple functions in one fish file

If I put a file called myfunc.fish in a directory called functions, and it includes a single function called myfunc, then fish will locate it if I type myfunc as a command.
What about if I want to have a bunch of short functions in one file? How do I "include" them?
source is how you include files.
Say you have a collection of functions thing1, thing2, etc. in a single file ~/mystuff/things.fish that you want to make available. Two good approaches are:
You can use the autoloading machinery: make the files functions/thing1.fish, functions/thing2.fish, etc. each with the same contents:
source ~/mystuff/things.fish
But a simpler approach is to just put that source line into your ~/.config/fish/config.fish file. Then it will be executed for each session.

Embed contents of source file inside source block in an org mode document (latex)

In pseudo-code I'd like to do the following in my org-mode file:
#+BEGIN_src python
[[./a_python_script_whose_contents_i_want_in_my_document.py]]
#+END_src
i.e. have the entire contents of a separate file be embedded in my org-mode document when I export it to latex.
How do I embed the contents of a separate file within an org-mode document, and have that content be formatted as source code when exporting?
There is no way to do that in org-mode with a source block that I know of. This will give you what you want if you have minted setup:
\inputminted{python}{your-script.py}
or if you use lsting
\lstinputlisting[language=Python]{source_filename.py}

How do I call a c function from inside a mex file in Matlab?

I have a mexFunction defined in a .c file, written in the regular mex wrapper format. I would like to be able to call another function, written in C, from inside that first function. How can I do this? Do I need to create a regular .c file and just include it at the beginning of the first file? I would like to be able to pass variables from within the mex function to this secondary C function.
The documentation for mex has two subsections that describe how to build a MATLAB extension when the source code is spread over multiple source files. Mostly, all you need to do is:
mex mexname.c helper1.c helper2.o
The result is automatically named according to the first file passed in.
For more information, read the documentation sections "Build MEX-File from Multiple Source Files" and "Create and Link to Separate Object Files". There are also sections discussing using libraries.

In org-mode, how do I include other .org files from a (main) .org file?

I want to place some customization codes in a separate file, and include it from other files later. For example, file config.org has a single line #+MATHJAX: align:"left" mathml:t. How do I include it in another .org file abc.org so that the net-effect is exactly same as I write that #+MATHJAX line directly in abc.org?
Use #+setupfile: /path/to/config.org documented here.
The #+INCLUDE directive can include another file with export options (but it cannot affect the configuration of the enclosing file, since it is only for export purposes). Use it like:
#+INCLUDE: "/path/to/config.org"