How can I use Telescope.nvim to complete a path in insert mode? - neovim

Fzf.vim implements a fuzzy finder in insert mode, extending the native ins-completion functionality.
For example: in insert mode, we can map <c-x><c-f> to enable Fzf.vim to fuzzy find and insert file names with relative paths (fzf-complete-path). The same functionalities are implemented for words (fzf-complete-word) and lines (fzf-complete-line) completions.
Here are the Fzf.vim mapping example of these functions:
" Insert mode completion
imap <c-x><c-k> <plug>(fzf-complete-word)
imap <c-x><c-f> <plug>(fzf-complete-path)
imap <c-x><c-l> <plug>(fzf-complete-line)
How can I set the same behavior with Telescope.nvim?

You can define a custom action and map it to a key to execute it in Telescope.
I've written a set of actions for this task (to insert file paths in the current buffer): telescope-insert-path.nvim
You just need to make your custom mappings in the require'telescope'.setup().
local path_actions = require('telescope_insert_path')
require('telescope').setup {
defaults = {
mappings = {
n = {
["pi"] = path_actions.insert_relpath_i_insert,
["pI"] = path_actions.insert_relpath_I_insert,
["pa"] = path_actions.insert_relpath_a_insert,
["pA"] = path_actions.insert_relpath_A_insert,
["po"] = path_actions.insert_relpath_o_insert,
["pO"] = path_actions.insert_relpath_O_insert,
["Pi"] = path_actions.insert_abspath_i_insert,
["PI"] = path_actions.insert_abspath_I_insert,
["Pa"] = path_actions.insert_abspath_a_insert,
["PA"] = path_actions.insert_abspath_A_insert,
["Po"] = path_actions.insert_abspath_o_insert,
["PO"] = path_actions.insert_abspath_O_insert,
["<leader>pi"] = path_actions.insert_relpath_i_visual,
["<leader>pI"] = path_actions.insert_relpath_I_visual,
["<leader>pa"] = path_actions.insert_relpath_a_visual,
["<leader>pA"] = path_actions.insert_relpath_A_visual,
["<leader>po"] = path_actions.insert_relpath_o_visual,
["<leader>pO"] = path_actions.insert_relpath_O_visual,
["<leader>Pi"] = path_actions.insert_abspath_i_visual,
["<leader>PI"] = path_actions.insert_abspath_I_visual,
["<leader>Pa"] = path_actions.insert_abspath_a_visual,
["<leader>PA"] = path_actions.insert_abspath_A_visual,
["<leader>Po"] = path_actions.insert_abspath_o_visual,
["<leader>PO"] = path_actions.insert_abspath_O_visual,
-- Additionally, there's normal mode mappings for the same actions:
-- ["<leader><leader>pi"] = path_actions.insert_relpath_i_normal,
-- ...
}
}
}
}

Related

Access data in Core Data using relationships and predicate

I am using Core data to store two databases that contain a relationships.
There is a logbook database and a IFRApproaches database.
A logbook entry can have multiple approaches.
An approach can only be linked to one logbook entry.
Attached is screenshots of my data model and relationships.
When the "submit" button is pressed this is the code to save the entry to the logbook, and the approaches as well.. I need the approaches (how ever many) associated with a singular entry. My question is How I can use a predicate to query the database at a later time for all the approaches associated with a various entry.
lazy var newEntry = Logbook(context: LoadData.shared.context)
if errorCount == 0 {
if modifyEntry == false {
if entryHolding.date == nil {
newEntry.date = Date()
} else {
newEntry.date = entryHolding.date
}
newEntry.aircraftID = entryHolding.aircraftID
newEntry.aircraftSelect = LoadData.shared.aircraftArray[aircraftArrayIndexPath!.row]
newEntry.categoryAndClass = newEntry.aircraftSelect?.categoryAndClass
newEntry.typeCode = entryHolding.typeCode
newEntry.from = entryHolding.from
newEntry.to = entryHolding.to
newEntry.route = entryHolding.route
newEntry.totalTime = entryHolding.totalTime
newEntry.pic = entryHolding.PIC
newEntry.sic = entryHolding.SIC
newEntry.solo = entryHolding.solo
newEntry.dual = entryHolding.dual
newEntry.crossCountry = entryHolding.crossCountry
newEntry.night = entryHolding.night
newEntry.simInstrument = entryHolding.simInstrument
newEntry.actualInstrument = entryHolding.actualInstrument
newEntry.hold = Int16(entryHolding.hold)
newEntry.dayLanding = Int16(entryHolding.dayLanding)
newEntry.nightLanding = Int16(entryHolding.nightLanding)
newEntry.bfr = entryHolding.BFR
newEntry.checkride = entryHolding.checkRide
newEntry.ipc = entryHolding.IPC
newEntry.comments = entryHolding.comments
for i in 0..<approach.count {
var newApproach = IFRApproaches(context: LoadData.shared.context)
newApproach.airport = approach[i].airportID
newApproach.typeOfApproach = approach[i].type
newApproach.runway = approach[i].runwayNum
//newApproach.entry = newEntry
newEntry.addToApproaches(newApproach)
LoadData.shared.approachArray.append(newApproach)
}
LoadData.shared.entryArray.append(newEntry)
LoadData.shared.saveData()

OPC UA.NET custom Node Manager creating

I'm trying to use UA-.NETStandardLibrary by OPC Foundation to create my own OPC UA Server that will maintain some variables.
I've created a server class inherited from StandardServer and node manager inherited from CustomNodeManager2.
There were some node managers in their examples, I removed them and add my own one. The server starts normally and doesn't contain any nodes except from standard ones, as planned. So, my problem is how to create my own variable node from code (not from xml, as in examples) and be able update its value on demand.
For example, I want to add a folder with couple of nodes inside.
Does anyone have a code snippet which demonstrates how to do it? I don't want anybody write it for me, I will appreciate only if you just tell me about a right way to make it.
Thanks a lot.
I am pretty sure the snippets you are looking for are included. Here is my testing code and I am 100% positive, I didn't write the second piece of code. Anyway, if this helps you...
{
var ticker_seq = createVariable(myFolder, "MyFolder/Ticker", "Ticker", BuiltInType.UInt64, ValueRanks.Scalar);
variables.Add(ticker_seq);
subscriptions.Add(clock.Ticker.Subscribe(val =>
{
lock (Lock)
{
ticker_seq.Value = val;
ticker_seq.Timestamp = DateTime.UtcNow;
ticker_seq.ClearChangeMasks(SystemContext, false);
}
}));
}
and creation
private BaseDataVariableState createVariable(NodeState parent, string path, string name, NodeId dataType, int valueRank)
{
BaseDataVariableState variable = new BaseDataVariableState(parent);
variable.SymbolicName = name;
variable.ReferenceTypeId = ReferenceTypes.Organizes;
variable.TypeDefinitionId = VariableTypeIds.BaseDataVariableType;
variable.NodeId = new NodeId(path, NamespaceIndex);
variable.BrowseName = new QualifiedName(path, NamespaceIndex);
variable.DisplayName = new LocalizedText("en", name);
variable.WriteMask = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
variable.UserWriteMask = AttributeWriteMask.DisplayName | AttributeWriteMask.Description;
variable.DataType = dataType;
variable.ValueRank = valueRank;
variable.AccessLevel = AccessLevels.CurrentReadOrWrite;
variable.UserAccessLevel = AccessLevels.CurrentReadOrWrite;
variable.Historizing = false;
variable.Value = 0;
variable.StatusCode = StatusCodes.Good;
variable.Timestamp = DateTime.UtcNow;
if (parent != null)
{
parent.AddChild(variable);
}
return variable;
}
creating the folder:
private FolderState CreateFolder(NodeState parent, string path, string name)
{
FolderState folder = new FolderState(parent);
folder.SymbolicName = name;
folder.ReferenceTypeId = ReferenceTypes.Organizes;
folder.TypeDefinitionId = ObjectTypeIds.FolderType;
folder.NodeId = new NodeId(path, NamespaceIndex);
folder.BrowseName = new QualifiedName(path, NamespaceIndex);
folder.DisplayName = new LocalizedText("en", name);
folder.WriteMask = AttributeWriteMask.None;
folder.UserWriteMask = AttributeWriteMask.None;
folder.EventNotifier = EventNotifiers.None;
if (parent != null)
{
parent.AddChild(folder);
}
return folder;
}

PSI update resource custom field with lookup table (Project Server)

Can someone show me a code to update a enterprise resource custom field with lookup table ? Already ran the internet looking for some sample code but did not succeed.
You can create and update a custom field with a lookup table using the below code . But we can not update or delete builtin custom fields
var projContext = new ProjectContext(projectServerUrl);
CustomFieldCollection CustomField = projContext.CustomFields;
EntityTypes Entitytype = projContext.EntityTypes;
LookupTableCollection lookupTables = projContext.LookupTables;
projContext.Load(CustomField);
projContext.Load(Entitytype);
projContext.Load(lookupTables);
projContext.ExecuteQuery();
CustomFieldCreationInformation NewfieldInfo = new CustomFieldCreationInformation();
NewfieldInfo.Id = new Guid();
NewfieldInfo.Name = "The Name";
NewfieldInfo.Description = "The Description";
NewfieldInfo.IsWorkflowControlled = true;
NewfieldInfo.IsRequired = true;
NewfieldInfo.IsEditableInVisibility = false;
NewfieldInfo.IsMultilineText = false;
LookupTable lookuptable = lookupTables.ToList().Find(x => x.Name == "LookupTableName");
projContext.Load(lookuptable);
projContext.ExecuteQuery();
NewfieldInfo.LookupTable = lookuptable;
NewfieldInfo.EntityType = Entitytype.ProjectEntity;
NewfieldInfo.FieldType = CustomFieldType.TEXT;
projContext.CustomFields.Add(NewfieldInfo);
projContext.CustomFields.Update();
projContext.ExecuteQuery();

Overriding image width with updateExportSettings

I have cross posted on the Adobe Forums.
Writing my first lightroom plugin, I have created a minimal example which should set the photo width here and included below. However I can not get the image to be the 400 x 400 specified.
ExportFilterProvider400.lua:
local LrView = import 'LrView'
local bind = LrView.bind
--------------------------------------------------------------------------------
-- This function will create the section displayed on the export dialog
-- when this filter is added to the export session.
local function sectionForFilterInDialog( f, propertyTable )
return {
title = LOC "$$$/SDK/MetaExportFilter/SectionTitle=400x400 Filter",
}
end
--------------------------------------------------------------------------------
-- Example on updating export settings
local function updateExportSettings( exportSettings )
exportSettings.LR_size_maxHeight = 400
exportSettings.LR_size_maxWidth = 400
exportSettings.LR_size_doConstrain = true
end
--------------------------------------------------------------------------------
return {
sectionForFilterInDialog = sectionForFilterInDialog,
updateExportSettings = updateExportSettings , --Does this work
}
Info.lua:
return {
LrSdkVersion = 3.0,
LrSdkMinimumVersion = 1.3,
LrPluginName = "400x400 Export",
LrToolkitIdentifier = 'sample.export400x400',
LrExportFilterProvider = {
title = LOC "$$$/SDK/MetaExportFilter/Sample=400x400 Size", -- the string that appears in the export filter section of the export dialog in LR
file = 'ExportFilterProvider400.lua', -- name of the file containing the filter definition script
id = "metadata1", -- unique identifier for export filter
},
VERSION = { major=5, minor=0, revision=0, build=907681, },
}
Adobe Lightroom can load the plugin, and add it to the export session, but the updateExportSettings do not seem to take effect. Tested in Lightroom 5.3.
Rob Cole on the Adobe SDK forum has pointed out that updateExportSettings is used by 'Export Service providers' to preset export settings.
'Export Filter providers' should use renditionOptions as part of postProcessRenderedPhotos.
After some trial and error I have this minimal example,
Info.lua (no change):
return {
LrSdkVersion = 3.0,
LrSdkMinimumVersion = 1.3, -- minimum SDK version required by this plugin
LrPluginName = "400x400 Export",
LrToolkitIdentifier = 'sample.export400x400',
LrExportFilterProvider = {
title = LOC "$$$/SDK/MetaExportFilter/Sample=400x400 Size",
file = 'ExportFilterProvider400.lua',
id = "metadata1", -- unique identifier for export filter
},
VERSION = { major=5, minor=0, revision=0, build=907681, },
}
ExportFilterProvider400.lua:
local LrView = import 'LrView'
local bind = LrView.bind
local function sectionForFilterInDialog( f, propertyTable )
logger:info('Called sectionForFilterInDialog')
return {
title = LOC "$$$/SDK/MetaExportFilter/SectionTitle=400x400 Filter",
}
end
local function postProcessRenderedPhotos( functionContext, filterContext )
local renditionOptions = {
filterSettings = function( renditionToSatisfy, exportSettings )
exportSettings.LR_size_maxHeight = 400
exportSettings.LR_size_maxWidth = 400
exportSettings.LR_size_doConstrain = true
end
}
for sourceRendition, renditionToSatisfy in filterContext:renditions( renditionOptions ) do
-- Wait for the upstream task to finish its work on this photo.
local success, pathOrMessage = sourceRendition:waitForRender()
end
end
--------------------------------------------------------------------------------
return {
sectionForFilterInDialog = sectionForFilterInDialog,
postProcessRenderedPhotos = postProcessRenderedPhotos,
}

zend router optimization

How can I optimize all of these routes into one. As we do in .htaccess file.
routes.addemails.type = "Zend_Controller_Router_Route_Regex"
routes.addemails.route = "campaign/email/add"
routes.addemails.defaults.module = campaignManagement
routes.addemails.defaults.controller = Email
routes.addemails.defaults.action = add
routes.updateEmail.type = "Zend_Controller_Router_Route_Regex"
routes.updateEmail.route = "campaign/email/edit/?([a-zA-Z0-9_-]+)?"
routes.updateEmail.defaults.module = campaignManagement
routes.updateEmail.defaults.controller = Email
routes.updateEmail.defaults.action = edit
routes.updateEmail.map.key = 1
routes.delEmail.type = "Zend_Controller_Router_Route_Regex"
routes.delEmail.route = "campaign/email/delete/?([a-zA-Z0-9_-]+)?"
routes.delEmail.defaults.module = campaignManagement
routes.delEmail.defaults.controller = Email
routes.delEmail.defaults.action = delete
routes.delEmail.map.id = 1
I've not set up a route using a config file, but at a glance try:
routes.emails.route = "campaign/email/(add|edit|delete)/?([a-zA-Z0-9_-]+)?"
routes.emails.map.action = 1
routes.emails.map.id = 2
I am assuming that the map.* are the variables in the url (so action is the first bit of regex, with id being the second bit of regex. Correct me if I'm wrong).