Friday, December 23, 2022

CLCL Customization for Emacs

Way back in 2017 I wrote an introduction to CLCL1, the clipboard manager that I prefer.  That post described how to add the supplementary Edit tool.  Today I’ll describe how to make CLCL work with Emacs.

By default, CLCL is set up to “listen” to the keystrokes Ctrl-x and Ctrl-c for pushing a selection to its stack of clipboard items, and Ctrl-v for popping the latest item into the focused application.  But Emacs’ standard keystrokes are Ctrl-w for “cutting,” Alt-w for “copying,” and Ctrl-y for “pasting.”  The terms “cutting,” “copying,” and “pasting” are in quotations because Emacs uses “killing” for “cutting” and “yanking” for “pasting.”2   And the keystrokes are described in Emacs-speak as C-w and C-y respectively.  The Emacs function “kill-ring-save” is like copy; it’s bound to M-w on my system.3

Anyway, to get a CLCL item yanked into the Emacs buffer, I add the Ctrl-y keystroke to CLCL.  You can do this on the Key tab of the Options dialog while Emacs is open.  Here's how.

Click the Add... button and scroll the Present Window List until you find a row whose title matches the text in the title bar of your Emacs application.  For me, that’s “GNU Emacs 25.2.1: *scratch*”, which is shown highlighted below.  Select that line and then click the down arrow button (or just double-click the line) to transfer the settings into the edit portion of the dialog box.


The Emacs title bar may include the name of the buffer.  In my example, that’s “*scratch*.”  But since the buffer name will vary, we need to replace it with the asterisk wildcard.

Click in the textbox below Copy and press Ctrl-w.4  Likewise, click in the textbox below Paste and click Ctrl-y.  The dialog should look similar to the one below.  Note that CLCL shows uppercase versions of W and Y in the Copy and Paste boxes; if you had pressed Ctrl-Shift-W it would display Ctrl + Shift + W instead.  OK your way out.


Now when you choose an item from CLCL while visiting a buffer in Emacs, it will be yanked into the buffer as expected.

Do you have a CLCL tip that you’d like to share?  Please let me know.  Add a comment below or email me.


1 https://ludditegeek.blogspot.com/2017/11/introduction-to-clcl-tools.html

2 And to further confuse the issue, Emacs maintains it own “clipboard” which is called the “kill ring.”  Somehow, Emacs on Windows will yank from the Windows clipboard or yank from its kill ring depending on which was modified last.

3 Please see https://www.emacswiki.org/emacs/CopyAndPaste for more details.

4 Actually, configuring Copy not not be necessary.  Emacs on Windows seems to kill to the Windows clipboard, and CLCL adds each new clipboard item to its stack.

Friday, December 09, 2022

Get Path to Current LibreOffice Spreadsheet

There are two comments related to the previous post:
  1. The blood draw wasn’t scheduled for the next morning. It was for the following morning! What a dummy I am!
  2. The code that I use in LibreOffice Calc to return the Current Working Directory can be found below. I call it with this worksheet function as an argument: CELL("FILENAME",$A$1).  Please note that the module in which this resides has the following statement at the top: Option VBASupport 1

Function LG_GetPath(s As String) As String

' 2019-02-26 LG  Created, mostly to derive Current Working Directory
	Dim sTemp As String
	Dim i As Long, j As Long
	' MsgBox "Contents of s: " & s
	If IsNull(s) Then
    	LG_GetPath = "ERROR"
    Else
    	sTemp = CStr(s)
    	i = InStr(s, "///") + 3
    	j = InStrRev(s, "/")
    	j = j - i
    	If j > 0 Then
    		sTemp = Mid(s, i, j) & "/"
    		LG_GetPath = sTemp
    	Else
    		LG_GetPath = "ERROR"
    	EndIf
    EndIf	
End Function ' LG_GetPath

Wednesday, December 07, 2022

High Blood Pressure vs. Computer Use -- Correlation?

Tonight I prepared for a 7:20AM fasting blood draw. Here’s how.

I have an outstanding balance with the lab, so I decide to pay it online and add a record to my database of paid medical balances.

I fire up my brand new laptop and navigate to the lab’s patient portal to accesse my account.

But before I pay any medical bill, I always verify that the balance does not exceed the Patient Responsibility as determined on the Insurance Provider’s Explanation of Benefits (EOB). So I also go to the insurance company website. While at the login prompt, I open my password manager to get the password for the site.

Unfortunately, the site rejects the username / password combination. The password had been created in 2018, so it must have expired.

At this point I could just reset the password. But then I would need to update both my work computer and the old computer. So I decide to start up my old, slow laptop and check the password manager on that computer. But the password manager offers the same old password for that site.

That’s not a problem. All I have to do is open Chrome, in which I save nearly all my passwords. But Chrome is running extremely slowly; seconds turn into minutes, so I take a break to feed the animals.

After I feed the animals, Chrome finally is loaded, and I find the new password in its password manager. I write that down on the invoice and transfer it over to the new computer via “SneakerNet.”

And this is where things spiraled into high blood pressure territory. The insurance company decided it was time to do maintenance on its website; it refused to display the login page any more!

I decide to call the insurance company, which is open after hours and also a few time zones behind me. Hold times are long. “Of course they are,” I told myself. “No one can log into the website!”

Finally, an agent picks up. “Hi, I just wanted to verify a Patient Responsibility – I can’t get into the website to do it.” The agent says, “I’m sorry but I can’t get that for you -- our computers are down. But they’ll be back up tomorrow morning.” “Oh, you too, huh?”

So then I decide that I’d just pay the darn balance. I’d rather pay online and download a receipt for my records than pay in person and get a paper receipt.

I switch tabs back to the lab’s invoice of my previous blood draw, the one I need to pay. But the information is gone – too much time had elapsed! So I’m required to re-enter the account details. I do that, and I’m able to transact the payment easily.

Next, I want to enter a record of the transaction in my database. I have a flat file database implemented in spreadsheet form with LibreOffice’s Calc. A brand new installation of LibreOffice, it loads quickly. Unfortunately the links to all my receipts and EOBs are showing up as #NAME. Now what?

It takes a while, but I figure out that I use =CELL(“FILENAME”, $A$1) to obtain the spreadsheet’s full path and file name. And then I use a home made function LG_GetPath() to strip away the spreadsheet’s file name and extension, returning a string that contains just the drive letter and directory. It’s this string (CWD) that prefaces all the links to the receipts and EOBs.

I go back to the old computer, open the Macro Editor, export the module, email it to myself (in case I can’t get it through the home network) and enter it into the LibreOffice installation on my new computer.

Finally I’m able to enter a record of the bill payment, the last step of my procedure for paying medical bills.

How long did this take? I recall that I finished feeding the cats at about 6:30PM and that I was able to finish my supper at 7:30Pm (thereby reducing the 12 hour fast to eleven-and-change). Given that it took me at least 15 minutes to eat, the process took nearly 45 minutes.

But from the way my heart was beating and the arteries throbbing in my neck, I’d say the time that was wasted was secondary to the increase in blood pressure.

And now, exactly eleven hours before tomorrow morning’s fasting blood draw, I’m quaffing the dregs of a Murphy’s Irish Stout.

We do not need medication to control blood pressure; we need new lives.

Friday, December 02, 2022

Add Command Prompt Here to Explorer Without Mucking About With the Registry

Windows 10 computers are missing the “Open Command Prompt Here” on the shortcut menu.

You can find a registry change online that will bring it back. But that “fix” involves changing the Permissions / Ownership of that part of the registry, so I declined to try it.

Instead I came up with a solution that uses the SendTo feature to call a batch file that calls CMD with the /K switch. To use it, create a batch file in your SendTo directory called OpenCMD.cmd. Add the content below, between the “BEGIN--------” and “END--------” tokens, and save it. Then Right-Click any file, choose SendTo OpenCMD.cmd, and a command prompt will be opened in the directory in which that file resides (if the path is on a local hard drive or mapped drive).

The SendTo directory can be found under your user profile; the <UN> in the path below is your user name:

C:\Users\<UN>\AppData\Roaming\Microsoft\Windows\SendTo

You can also enter the following in the explorer address bar to navigate to SendTo: shell:SendTo

Here’s the batch file source code. Please note that most of the lines are either comments (which start with REM) or debugging statements (which start with Echo). In fact the only lines that are necessary are the ones between the labels :OpenCMD and :END.  And please don't include the “BEGIN--------” and “END--------” tokens

Begin--------

REM OpenCMD.cmd (c) 2022 Luddite Geek

REM Opens the command prompt in the directory of the given path

REM

REM 2022-11-04 LG Created.

GOTO OpenCMD

GOTO BEGIN

cmd /?

:BEGIN

@echo off

Echo %0 %1

Echo DRIVE: %~d0

Echo PATH: %~p0

Echo NAME: %~n0

Echo EXT: %~x0

Echo.

Echo Drive and Path of parameter 1: %~dp1

pause


:OpenCMD

%~d1

cd %~dp1

CMD /D /K CLS

:END

End--------