In neovim, how do I get a file to open at the same line number I closed it at last time? - neovim

au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
This code is valid in vim. It is the syntax of vimscript. It can also work in neovim's configuration file init.vim. how can I achieve the same effect in init.lua?

Tested on 0.7.2, if not available, the version may be too low.
vim.api.nvim_create_autocmd("BufReadPost", {
pattern = {"*"},
callback = function()
if vim.fn.line("'\"") > 1 and vim.fn.line("'\"") <= vim.fn.line("$") then
vim.api.nvim_exec("normal! g'\"",false)
end
end
})

Related

How to use if condition in selenium IDE

3 login based questions in the website to be automated
I need correct code to automate these.
enter image description here
When using "if ..." Commands in test steps in Selenium IDE for Chrome, you need to remember the following:
Use "if ... end" to form a single branch of test steps.
Use "if ... else ... end" to form two branches of test steps.
Use "if ... else if ... else ... end" to form multiple branches of test steps.
Use JavaScript Boolean expression syntax to specify conditions to "if" and "else if" commands.
${variable} is allowed in condition expressions.
Here is a sample test called "Condition" on how to use variables:
1 execute script | return (new Date()).getDay(); | day
2 echo | ${day}
3 if | ${day} < 1
4 echo | Sunday
5 else if | ${day} > 5
6 echo | Saturday
7 else
8 echo Weekday
9 end
Here is the log output when you execute the above test.
1. executeScript on return (new Date()).getDay(); with value day OK
echo: 0
3. if on ${day} < 1 OK
echo: Sunday
5. elseIf on ${day} > 5 OK
7. else OK
9. end OK

Save job output from SDSF into a PDS and using ISPF functions in REXX

We periodically runs jobs and we need to save the output into a PDS and then parse the output to extract parts of it to save into another member. It needs to be done by issuing a REXX command using the percent sign and the REXX member name as an SDSF command line. I've attempted to code a REXX to do this, but it is getting an error when trying to invoke an ISPF service, saying the ISPF environment has not been established. But, this is SDSF running under ISPF.
My code has this in it (copied from several sources and modified):
parse arg PSDSFPARMS "(" PUSERPARMS
parse var PSDSFPARMS PCURRPNL PPRIMPNL PROWTOKEN PPRIMCMD .
PRIMCMD=x2c(PPRIMCMD)
RC = isfquery()
if RC <> 0 then
do
Say "** SDSF environment does not exist, exec ending."
exit 20
end
RC = isfcalls("ON")
Address SDSF "ISFGET" PPRIMPNL "TOKEN('"PROWTOKEN"')" ,
" (" VERBOSE ")"
LRC = RC
if LRC > 0 then
call msgrtn "ISFGET"
if LRC <> 0 then
Exit 20
JOBNAME = value(JNAME.1)
JOBNBR = value(JOBID.1)
SMPDSN = "SMPE.*.OUTPUT.LISTINGS"
LISTC. = ''
SMPODSNS. = ''
SMPODSNS.0 = 0
$ = outtrap('LISTC.')
MSGVAL = msg('ON')
address TSO "LISTC LVL('"SMPDSN"') ALL"
MSGVAL = msg(MSGVAL)
$ = outtrap('OFF')
do LISTCi = 1 to LISTC.0
if word(LISTC.LISTCi,1) = 'NONVSAM' then
do
parse var LISTC.LISTCi . . DSN
SMPODSNS.0 = SMPODSNS.0 + 1
i = SMPODSNS.0
SMPODSNS.i = DSN
end
IX = pos('ENTRY',LISTC.LISTCi)
if IX <> 0 then
do
IX = pos('NOT FOUND',LISTC.LISTCi,IX + 8)
if IX <> 0 then
do
address ISPEXEC "SETMSG MSG(IPLL403E)"
EXITRC = 16
leave
end
end
end
LISTC. = ''
if EXITRC = 16 then
exit 0
address ISPEXEC "TBCREATE SMPDSNS NOWRITE" ,
"NAMES(TSEL TSMPDSN)"
I execute this code by typing %SMPSAVE next to the spool output line on the "H" SDSF panel and it runs fine until it gets to this point in the REXX:
114 *-* address ISPEXEC "TBCREATE SMPDSNS NOWRITE" ,
"NAMES(TSEL TSMPDSN)"
>>> "TBCREATE SMPDSNS NOWRITE NAMES(TSEL TSMPDSN)"
ISPS118S SERVICE NOT INVOKED. A VALID ISPF ENVIRONMENT DOES NOT EXIST.
+++ RC(20) +++
Does anyone know why it says I don't have a valid ISPF environment and how I can get around this?
I've done quite a bit in the past with REXX, including writing REXX code to handle line commands, but this is the first time I've tried to use ISPEXEC commands within this code.
Thank you,
Alan

Matlab Codgen: Build error: 'lcclnk64' is not recognized as an internal or external command, operable program or batch file

This question is on error occurring while C code generation from MATLAB Script.
I want to convert my MATLAB script to standalone executable file. When I ran my file (Code_check.m) with 'codegen' command I got following error in target build log:
'lcclnk64' is not recognized as an internal or external command, operable program or batch file gmake: * [Code_Check_mex.mexw64] Error 1
There are other lines in target build log, commands which probably show build of c file for matlab commands (like randi,fprintf etc.)
I have checked script with %#codegen inclusion and it gives no error. While running with codegen, above mentioned error occurs. I have checked if matlab path is included in system variables path, and it is. So I have no clue how to go on.
Can somebody give some insight on how to solve this problem?
Thanks in advance
My .m script is as follows: (I apologize for long question)
% code
%#codegen
function [Output] = Code_Check
data = coder.load('EMEA_code_prep.mat');
temp_wt = find(data.Wash_cycle_data( randi(2131), : ));
fileID = fopen('Results.txt','w');
if length( find(data.Wash_cycle_data( randi(2131), : )) ) == 1;
fprintf(fileID,'%20s\n','Wash cycle type');
fprintf(fileID,'%20s\n',data.Wash_type(temp_wt,:));
else
fprintf(fileID,'%20s\n','Wash cycle type');
fprintf(fileID,'%20s\n','N/A for this trial');
end
fprintf(fileID,'%20s\n','Speen Speed');
temp_SP = data.un_SP(find(data.idx_SP( randi(2131), : )));
fprintf(fileID,'%12.8f\n',temp_SP(1) );
temp_temp_ll = find( data.Loading_level_data( randi(2131),: ) );
if length(temp_temp_ll) == 1
Output(2,3) = Loading_level(temp_temp_ll);
fprintf(fileID,'%20s\n','Loading Level');
fprintf(fileID,'%20s\n',data.Loading_level(temp_temp_ll,:));
elseif length(temp_temp_ll) == 0
%Output(2,3) = NAvar;
fprintf(fileID,'%20s\n','Loading Level');
fprintf(fileID,'%20s\n','N/A');
else
temp_temp = data.Loading_level(temp_temp_ll);
fprintf(fileID,'%20s\n','Loading Level');
fprintf(fileID,'%40s\n',temp_temp(1));
end
temp_temp_f = find( data.Fabric_type_data( randi(2131),: ) );
if length(temp_temp_f) == 1
fprintf(fileID,'%20s\n','Fabric Type');
fprintf(fileID,'%20s\n',data.Fabric_type(temp_temp_f,:));
elseif length(temp_temp_f) == 0
fprintf(fileID,'%20s\n','Fabric Type');
fprintf(fileID,'%20s\n','N/A');
else
temp_temp = data.Fabric_type(temp_temp_f);
fprintf(fileID,'%20s\n','Fabric Type');
fprintf(fileID,'%40s\n',temp_temp(1));
end
temp_temp_c = find(data.Color_data( randi(2131),: ) );
if length(temp_temp_c) == 1
fprintf(fileID,'%20s\n','Color');
fprintf(fileID,'%20s\n',data.Color(temp_temp_c,:));
elseif length(temp_temp_c) == 0
fprintf(fileID,'%20s\n','Color');
fprintf(fileID,'%20s\n','N/A');
else
temp_temp = data.Color(temp_temp_c);
fprintf(fileID,'%20s\n','Color');
fprintf(fileID,'%40s\n',temp_temp(1));
end
fprintf(fileID,'%20s\n','Wash Results');
temp_WR = data.un_Wresults(find(data.idx_Wresults( randi(131), : )));
fprintf(fileID,'%12.8f\n',temp_WR(1));
fprintf(fileID,'%20s\n','Wash Results');
temp_Spr = data.un_Spresults(find(data.idx_Wresults( randi(131), : )));
fprintf(fileID,'%12.8f\n',temp_Spr(1));
Output = data.Title;
end
and Last few lines of target build log:
14 lcclnk64 -dll -L"C:\PROGRA~1\MATLAB\R2014b\sys\lcc64\lcc64\lib64" - L"C:\PROGRA~1\MATLAB\R2014b\extern\lib\win64\microsoft" -entry LibMain "Code_Check_mex_lccstub.obj" -s -o Code_Check_mex.mexw64 Code_Check_mexutil.obj Code_Check_data.obj Code_Check_initialize.obj Code_Check_terminate.obj Code_Check.obj randi.obj fopen.obj fileManager.obj fprintf.obj _coder_Code_Check_api.obj _coder_Code_Check_mex.obj _coder_Code_Check_info.obj libmx.lib libmex.lib libmat.lib libemlrt.lib libcovrt.lib libut.lib libmwblas.lib libmwmathutil.lib Code_Check_mex_mex.def
15 'lcclnk64' is not recognized as an internal or external command,
16 operable program or batch file.
17 gmake: *** [Code_Check_mex.mexw64] Error 1

Using a for loop to access Command Prompt

I want to call a function Christian.exe to the command line to act of a series of files that are indexed as "reentrant_008.sif" (8 is an example number).
"Christian.exe reentrant_00" & num & ".sif reentrant_00" & num & ".pgm" 0 2000 is the text that needs to be fed into the command prompt for the program to execute (num is an arbitrary number)
There are approximately 400 files, so I want to create a vbs code that calls the command prompt for each file until all the files have been accessed so far this is my code:
For
Dim cmdpath
num = CStr(i)
Set wshShell = WScript.CreateObject ("WSCript.shell")
If i < 10 Then
cmdpath = "Christian.exe reentrant_00" & num & ".sif reentrant_00" & num & ".pgm" 0 2000
Else
If i < 100 Then
cmdpath = "Christian.exe reentrant_0" & num & ".sif reentrant_0" & num & ".pgm" 0 2000
Else
cmdpath = "Christian.exe reentrant_" & num & ".sif reentrant_" & num & ".pgm" 0 2000
End If
End If
wshshell.run cmdpath
Next
Problem is that a new command prompt is being called for each file, which is slowing down my computer. How do I ensure that only one command window that addresses all my files is called?
If you look at the documentation for Run you will see two option arguments [intWindowStyle], [bWaitOnReturn]. If you want your EXE to wait before proceeding on the script change your call to this
wshshell.run cmdpath, 0, True
Where 0 will hide the window and True will wait for the program to finish before proceeding in the script. Depending on your needs you could change the number or remove it.
wshshell.run cmdpath,, True
Since you tagged your question with both vbscript and powershell I'm adding a PowerShell solution:
foreach ($i in 1..400) {
$num = "{0:d3}" -f $i
& Christian.exe "reentrant_${num}.sif" "reentrant_${num}.pgm" 0 2000
}
& is the call operator. I recommend using it whenever you run external commands in PowerShell, because otherwise you'll be in for a surprise when you try to run a command from a variable for the first time:
$christian = "Christian.exe"
$christian ... # <-- throws an error, because $christian contains a
# string, which is NOT automagically interpreted
# as a command by PowerShell
& $christian ... # <-- works
-f is the formatting operator, that allows you to create formatted string output. Since your command lines only differ by the zero-padding of the input and output files it's better to build the file names with pre-padded number strings.
I recommend doing the pre-padding in VBScript as well:
For i = 1 To 400
num = Right("000" & i, 3)
cmdpath = "Christian.exe reentrant_" & num & ".sif reentrant_" & num & _
".pgm" 0 2000
wshshell.run cmdpath, 0, True
Next

How do I manually generate text files for entire project to diff in Visual FoxPro (e.g. .sca, .vca, etc.)

The challenge is that I'm checking my FoxPro code into source control (using Mercurial, but that's not the focus of this question) and would like a quick way to get the FoxPro SCCTEXT output alongside the binary output without using the Tools > Options > Projects > Active source control provider functionality.
For an example of the kind of output I'm looking to generate, the VFPX source contains many of these text .sca, .vca, etc. files. Is there any way to generate these files on demand?
Rather than setting a source control provider, you can hack scctext.prg (which ships with VFP) and use a project hook to generate the files - see http://paulmcnett.com/scX.php for an example implementation using Subversion.
Edit: Have you looked at the Alternate SCCText on Codeplex
Also see http://www.foxpert.com/docs/cvs.en.htm for another perspective.
Here is the code I use to genereate SCCText files for every file in my Project file. Just open your Project (to make sure it is the Active Project, then run this prg file).
(Updated 2011-06-10: Added a new feature that will only build new SCC text files if the DateTime of the original source file is newer than the existing SCC file. Essentially, this new version only generates a new SCC file if the VFP source file has been changed since the last time this was run.)
lnResponse = MessageBox('Run SSCText to generate ascii code files?', 3, 'Generate SCC files?')
If lnResponse <> 6
Return
EndIf
*Clear All
*Release All
Set ClassLib to && Must clear them out, cause we're about to generate ascii files of them
lnCount = DoSCCTextOnProject()
? Chr(10)+Chr(13)
? 'Done. ' + Str(lnCount) + ' files processed.'
*----------------------------------------------------------------------
Procedure DoSCCTextOnProject
Local loFile, loProject, lnCount
lcSCCText = Home(1) + 'SCCText.prg'
lnCount = 0
If !File(lcSCCText)
Messagebox('Unable to find file ' + lcSCCText, 16, 'Error')
Return 0
Endif
Try
loProject = _vfp.ActiveProject
Catch To loEx
Endtry
If Type('loEx') = 'O'
Messagebox('There are no active projects', 64, 'Error')
Return 0
Endif
lcSkipFiles = 'LIST-FILES-TO-SKIP-HERE'
For Each loFile In loProject.Files
If Inlist(loFile.Type, 'V', 'K', 'R') and ;
!InList(Upper(JustFname(loFile.name)), Upper(lcSkipFiles)) ;
and Fdate(loFile.name, 1) > SCCFileDateTime(loFile.name)
? 'Generating: ' + loFile.Name
Do (lcSCCText) With loFile.Name
lnCount = lnCount + 1
Endif
Endfor
Return lnCount
*------------------------------------------------------------------
Procedure SCCFileDateTime(tcFile)
lcSCCFilename = Upper(Strtran(Upper(tcFile), '.SCX', '.SCA'))
lcSCCFilename = Strtran(lcSCCFilename, '.VCX', '.VCA')
lcSCCFilename = Strtran(lcSCCFilename, '.FRX', '.FRA')
If File(lcSCCFilename)
Return Fdate(lcSCCFilename, 1)
Else
Return {^1900-01-01 00:00:00}
EndIf
EndProc