Skip to main content

Posts

Showing posts from 2020

Emacs and MacOS Catalina

Catalina introduced a lot of security changes and the most intrusive is probably all the popups asking to give permission for apps to access directories under Home, like Documents. Worse still, apps which weren't written to handle the new security measures might just fail silently with no clues for the user. A solution is to give apps like Emacs "Full Disk Access" under "Security & Privacy" in Preferences, to give unfettered access to your files and avoid all the popups and silent failures. Sounds good, but that doesn't actually work for Emacs because "Emacs" in the app bundle is actually a Ruby script which decides which flavour of Emacs executable to run. This never mattered before, but it does under Catalina because MacOS thinks the executable is /usr/bin/ruby . Conventional wisdom is therefore to give "Full Disk Access" to Ruby. While this does work, I've always been uncomfortable giving all Ruby scripts full access

Brf-Mode 1.19 Has Been Released

This week I released a new version of Brf-Mode , an Emacs minor-mode that implements various features from the legendary programmer's editor Brief . You can get the new version from MELPA . New features are: Changed Window Resize (F2) to work exactly like in Brief, where the user first picks an edge and then uses the cursor keys to move that edge. Before the change, Window Resize just moved the window edge 1 column or row in the chosen direction. This was definitely more "Emacs-style", but harder to use without resorting to the (repeat) command. Added implementation of Brief's "Zoom Window Toggle" on M-F2. Documentation update to reflect the new features and some fixes to existing text. One of the things that prompted the new release was I found an old (very old) backup with the original Brief program on it. I was able to get it to run on the Mac using DOSBox , the cross-platform DOS game emulator. This is the first time for many years I've been able to

Merging Git Repositories

No project of significant size that I've ever seen has retained its initial structure. Restructuring projects is a fact of life, but unfortunately Git doesn't make it easy. Fundamentally this stems from the way Git works, treating changes as a succession of snapshots and not storing any other metadata. Of course this is part of what makes Git fast and efficient, but at the expense of making some common operations more difficult for users. Git really is a perfect 21st century illustration of the classic  "Worse Is Better"  paradigm of successful software 😀 Previously I discussed how to split a Git project apart into separate repositories . Now I'm going to discuss how to do the opposite and merge separate repositories into one. On the face of it, this would seem a simpler task as Git has powerful support for merging... Let's take the opposite example to my splitting apart article - say you have a main Git repo (ProjA) and a second repo (ProjB) in

On BBC Springwatch !

BBC Springwatch featured one of my Goldfinch pictures last night: Goldfinch on Springwatch Shame they spelt my name wrong though! See the original on Flickr.

My Work in new Top Trumps Birds of Prey Pack

The new Top Trumps "Birds of Prey" pack has my picture illustrating the Secretary Bird card 😀 Here's the original picture: From Flickr

Setting Environment Variables and the PATH on MacOS

Time Was setting environment variables and the PATH on a Mac running OSX was just like any other *IX.  However with successive OS releases Apple have changed how this works (more than once) and generally made it more difficult 😢  This article discusses how I go about setting environment variables on Mojave and Catalina. Why does this matter? MacOS doesn't add  /usr/local/bin to the PATH by default, which is unfortunate as most *IX-style programs you build yourself will be installed in there. If you only ever launch stuff from Terminal, all you have to do is set environment variables and the path from Shell startup files in the time immemorial fashion. However, this doesn't help with native Mac Apps like Emacs, which aren't launched from a shell and where you may still want to access custom environment variables and programs in /usr/local/bin . Setting the PATH In the past you could add to the path via /etc/paths (or paths.d ), however this no longer works i

Renaming Files in Git

Renaming Files I recently had to rename a lot of files in brf-mode for submission into MELPA . These files have 10+ years of version control history I wanted to keep. In the process I realised retaining all that history in Git isn't as simple as I thought 😀 I thought it was as simple as using git mv rather than filesystem  mv and Git would know everything had been renamed. It turns out I was wrong and I should have known that from my knowledge of how Git works 😖 In reality, Git works by storing snapshots rather than file or directory metadata and git mv is just a convenience shortcut for typing: $ mv <old name> <new name> $ git rm <old name> $ git add <new name> That's all there is to it! Now the "magic" happens when you git log or git blame a file and Git works out the file was renamed by diffing the contents.  If files have the same contents (within a certain threshold %) it thinks a rename happened. See here in the  Gi

The Strange Case of Emacs, # and the UK Keyboard

Programmers typing on the UK Mac keyboard have a problem with # # is commonly used in programming languages and the Mac UK layout puts # on ⌥ 3 (Alt-3), as opposed to Shift-3 on the US layout or Windows UK layout. This is a particular problem in Emacs, which interprets the ⌥ (Alt) key press as the Meta key and so Emacs receives M-3 instead of #. My first approach was just to make M-3 insert #: (define-key brf-mode-map "\M-3" (lambda () (interactive) (insert ?#))) This hoses bookmark 3 in brf-mode , but losing one bookmark seemed like a compromise I could live with. However it turns out this was a pretty dumb idea (😖), as it stops all the uses of # other than inserting, for example searching for # ! It also stops me typing the command for server-edit   ( C-x # ) , which is a very common usage for me. Looking around the web, people had some "creative solutions" for this problem: Inserting # handling into all the various keymaps This seems to be the m

Enable Mac Startup Chime

As has been widely reported, it looks like Catalina has brought back the the ability to enable the classic Mac startup chime. Personally I like the boot chime 😀 To enable: $ sudo nvram StartupMute=%00 To revert back to default: $ sudo nvram StartupMute=%01 Note that if you reset the NVRAM, you'll have to apply this setting again.

Git: Move Subdirectory to New Repository

I recently published my  Brief emulation mode for Emacs  to the MELPA  Emacs package repository. This is code I wrote well over twenty years ago and have been using daily since. I hadn't published it before partly because it was languishing in a sub-directory of my main Emacs repo (and partly because I never had the time before). To become a package in its own right though, it had to have its own repo. Splitting out a subdirectory to a new repo used to be a complex task in Git (usually involving complicated invocations of git filter-branch) , but these days it's reasonably straightforward with the git subtree command (well at least as straightforward as anything else in Git 😀). The other reason I like the subtree method is it's non-destructive - you can back out at any point and still get back to where you started, plus all the history is retained. Here's how it works: Step 1: Create a new branch in the main repo with just the sub-directory commits $ cd <

VirtualBox: How To Shrink VDI File

One area where Parallels is much better than VirtualBox is in the ease of compacting a VM disk to what's actually in use. I've found that VM disks just keep increasing in size, regardless of what you might delete. Parallels makes compacting easy - all you do is select " Shrink... " from the Parallels menu. The situation with VirtualBox is more complicated 😀 While there is a command line "compact" option, this relies on unused stuff being zero - which it won't be for things that got deleted... However there is a tool ( zerofree ) which you can run in the VM and it sets all the free space on the disk to zero, which can then be compacted in VirtualBox. Here are the steps I've been using: Step 1: Install zerofree in the VM (Linux in my case): $ sudo apt install zerofree Step 2: Empty Trash and delete unneeded files Step 3: Boot into a recovery session Enter root password. Step 4: Remount disk as read-only # mount -n -o remount,

VirtualBox: Install Guest Additions in Linux VM

As mentioned in my previous post, I found VirtualBox pretty easy to install and make work. My only real difficulty was figuring out how to install the "Guest Additions" on Linux, as this is poorly documented. The "Guest Additions" are the VirtualBox equivalent of the " *-tools " of the commercial VM's and provide closer integration between the VM and host environment, so you usually want to install them. Here are the steps I used to install the "Guest Additions" on Debian 8 & 9 with VirtualBox 6.1.*: Step 1: Prepare for building a kernel module $ sudo apt-get install build-essential module-assistant $ sudo m-a prepare Step 2: Run the Guest Additions install Click the VirtualBox Devices menu on the VM. Click " Insert Guest Additions CD image... " Run the installer: $ mount /media/cdrom $ sudo sh /media/cdrom/VBoxLinuxAdditions.run $ sudo reboot Step 3: Fix permissions issue with  shared  folders U

Convert Parallels Disk to VirtualBox VDI

I used to use the free Parallels Desktop Lite on the Mac App Store to host various Linux virtual machines for software testing purposes. Although I'd heard things about the company's business practices, I thought it was a pretty fair deal allowing people to run free OS's for free - you only had to pay to run Windows. However about a year ago they introduced a mandatory subscription (at £74 per annum) even to run Linux, in the guise of a normal software update. None of this was mentioned in the update info - Nice 😡 No worries I thought (this is the polite version) - I'll just restore the previous version from Time Machine and Bob was indeed my uncle. This plan worked fine until I upgraded to Catalina and sure enough Parallels would no longer run. Rather than pay the Parallels ransom, I decided to investigate the alternatives. After some research I settled on VirtualBox, a free open-source VM from Oracle. VirtualBox was surprisingly easy (for an open-source pro

New Start

As we're all in Lockdown for the foreseeable future, I decided to reactivate my (long neglected) blog and also to widen the scope to include my musings on tech subjects, as well as photographic ones 😀 Part of the reason is also my photographic stuff is really concentrated at  Flickr , 500px  and my  Portfolio website .