Neovim Telescope Read File Into Current File? - lua

Jumping on this lua-neovim bandwagon...Need help with Telescope, please.
In my old setup; I'd grab basic templates from my documents like:
<leader>gt :-1read ~/Documents/templates/
And then I just use vim's normal tab completion to get where I need to go, but with telescope's fuzzy search and preview window, this will go to the next level!
I can open my templates like this
lua require('telescope.builtin').find_files{ cwd = '~/Documents/templates/' }
I've tried several combos with :read and various brackets, to make it read the contents into the current file to no avail (just learning Lua now, so mostly just crash and bang methods)
I found this in the docs with vague mention to reading files
previewers.buffer_previewer_maker({filepath}, {bufnr}, {opts}) previewers.buffer_previewer_maker()
But I'm obviously missing something.
Ideally I'd want key combo in the mappings, that way I can open normally, or read it (bonus points if it inserts at the cursor) - along with the miriad of options already available.
mappings = {
i = {
["<C-n>"] = actions.cycle_history_next,
["<C-p>"] = actions.cycle_history_prev,
...
["<C-r>"] = actions.READ_FILE_INTO_BUFFER,
...
Anyways, I've spent way too long on this, and I'm sure one of you Lua/Neovim Geniuses will have the solution!
Thanks!

Related

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.

How to create and load a configuration file in dxl

I have a script which saves some files at a given location. It works fine but when I send this code to someone else, he has to change the paths in the code. It's not comfortable for someone who does not know what is in that code and for me to explain every time where and how the code should be changed.
I want to get this path in a variable which will be taken from the configuration file. So it will be easier for everyone to change just this config file and nothing in my code. But I have never done this before and could not find any information on how I can do this in the internet.
PS: I do not have any code and I ask about an ultimate solution but it is really difficult to find something good in the internet about dxl, especially since I'm new with that. Maybe someone of you already does that or has an idea how it could be done?
DXL has a perm to read the complete context of a file into a variable: string readFile (string) (or Buffer readFile (string))
you can split the output by \n and then use regular expressions to find all lines that match the pattern
^\s*([^;#].*)\s*=\s*(.*)\s*$
(i.e. key = value - where comment lines start with ; or #)
But in DOORS I prefer using DOORS modules as configuration modules. Object Heading can be the key, Object Text can be the value.
Hardcode the full name of the configuration module into your DXL file and the user can modify the behaviour of the application.
The advantage over a file is that you need not make assumptions on where the config file is to be stored on the file system.
It really depends on your situation. You are going to need to be a little more specific about what you mean by "they need to change the paths in the code". What are these paths to? Are they DOORS module paths, are they paths to local/network files, or are the something else entirely?
Like user3329561 said, you COULD use a DOORS module as a configuration file. I wouldn't recommend it though, simply because that is not what DOORS modules were designed for. DOORS is fully capable of reading system files in one line at a time as well as all at once, but I can't recommend that option either until I know what types of paths you want to load and why.
I suspect that there is a better solution for your problem that will present itself once more information is provided.
I had the same problem, I needed to specify the path of my configuration file used in my dxl script.
I solved this issue passing the directory path as a parameter to DOORS.exe as follow:
"...\DOORS\9.3\bin\doors.exe" -dxl "string myVar = \"Hello Word\"
then in my dxl script, the variable myVar is a global variable.

Sublime text 2: certain files should open in a different panel

I'm using Sublime Text 2 for Rails development. I love the editor so far, especially its customizability. Currently I'm getting used to a 2-panel workflow where I have various Rspec files open in the right panel, and the corresponding views, controllers etc. open in the left panel. But when I open new files, they frequently open in the wrong panel (the one I'm currently working in), and I have to drag them over to the left or right manually.
Here's my question: when I open a file, is it possible to make the file open in the right panel if the file name has "_spec" in it, and in the left panel otherwise?
I know that's a pretty specific adjustment. I'd appreciate any tips.
Yes it is possible via a plugin. If you have some time, I'd spend a little bit of it investigating the sublime text api. I've thrown something together that should work. It's only minimally tested, and not very robust. Though I think it should work for your use case. If it doesn't you can use making it just right part of exploring the ST api.
import sublime_plugin
import os
class OpenLocationListener(sublime_plugin.EventListener):
def on_load(self, view):
file_name = view.file_name()
window = view.window()
num_groups = window.num_groups()
if file_name is not None and num_groups >=2:
if "_spec" in os.path.basename(view.file_name()):
if window.active_group() == 0:
window.set_view_index(view, 1, 0)
window.focus_view(view)
else:
if window.active_group() == 1:
window.set_view_index(view, 0, 0)
window.focus_view(view)
Save the above in your Packages/User folder as <some name>.py The name doesn't matter, as long as you save it as a python file.
As a side not, unless you are using an ST2 only plugin, consider upgrading to ST3. Many plugins that are under active development may only be ST3 compatible. I wrote the above in ST3, so that's where I tested, though I don't believe there is anything ST3 specific about it.

I can't find where a string is getting defined -- any tricks to find its source?

I'm using:
Rails 3.2x
Spree 1.2
Ruby 1.9.3x
I'm trying to edit the title of one of my pages, and I cannot find where it is getting defined. It is showing up in my base ERB file as 'title', but that name is sufficiently generic to make it next to impossible to find where it is defined.
I have prodded everywhere I can think, I've tried searching for "title =", but nothing is working. I tried calling source_location on it, but that appears to only work on methods.
Any tricks for finding where a variable is defined?
I can't think of an elegant way. A dumb-but-probably-effective way would be to dump stack trace in your erb, then see what those locations are doing and if title is defined there. It has to enter somewhere between the start of program and invoking your erb.
When I can't find something, I use grep -ri some_string . at the command-line to recursively search all the content of the directory.
It's also a good tactic to let your editor search all the source code, since the ones worth using have the ability to search through all files in a directory.
it is created from a mixture of product names, a site config, and something else
An alternate trick is to add a HTML-comment section in your ERB file, and put the pertinent information for the components used to create the title into that section. Then, let the pages be generated and look inside the page's content to determine what table and row ID it is, the site_config filename, etc.
You really should be able to figure it out based on the parts that are concatenated to build the title and then search your database or files. That information isn't magically created out of thin air by Rails; Someone had to tell Rails how to define the title. But, people move on, or they don't document correctly, so try the embedded information trick.

How can I load a local file from embedded Rhino?

I'm using Rhino's context.evaluateString() to run some simple JavaScript from inside of Java. It's textbook right out of the Embedding Javascript guide:
String script = // simple logic
Context c = new ContextFactory().enterContext();
ScriptableObject scope = context.initStandardObjects();
Object o = context.evaluateString(scope, script, "myScript", 1, null);
ScriptableObject result = Context.jsToJava(o, ScriptableObject.class);
I'm not sure this is the current best-practice, because the main Rhino docs appear to be down, but it's working so far.
I'd like to be able to refer to a library in the working directory -- I see that Rhino shell supports load but I don't think this works in the embedding engine.
Is this possible? Is it documented anywhere? Ideally, I'd like to be able to just call something like load('other.js') and have it search directories I specify as a global property.
I have a sort-of answer that I don't really like, not least because it exposes what I'm pretty sure is a Rhino bug that drove me crazy for the last half hour:
eval("" + Packages.org.apache.commons.io.FileUtils.readFileToString(
new java.io.File("/the/local/root", "script.js");
));
{ That "" + ... is how I work around the bug -- if you eval() a Java String (such as is returned from the readFileToString call) without manually coercing it to a JavaScript native string, nothing appears to happen. The call just silently fails. }
This blindly reads an arbitrary file and evals it -- of course, this is what you do when you eval() from the Java side, so I don't worry about it too much.
Anyway, it's not elegant for a number of reasons, but it works. I'd love to hear a better answer!

Resources