0

I was using this init file on a NixOS machine.

It is important to note that parts of the file were written with use-package and other parts were a legacy from the classic imperative installation of packages: M-x, package-install, and tweaks on hooks and variables.

This weekend I started a new set-up in a new Macbook Air M1 for professional reasons. I must highlight that I am new to Mac.

As I was trying to make myself at home with Emacs in MacOS, I started to copy small snippets of my old config file and slightly migrate them to mac. As the process was going, I decided to use the opportunity to "code review" my own init file - especially to make it more declarative via use-package. The expectation was to make it more reproducible for future occasions.

Sometimes, especially after creating a declaration of a package not yet installed, there was a weird thing happening. I would receive the following messages on the mini-buffer area:

enter image description here

enter image description here

The funniest point was that after quitting (C-x C-c) and re-starting Emacs, things worked fine (as expected) and the error message would disappear!

And this problem/phenomenon happened multiple times. This is the new config file. See the diff.

Why did this happen? Is the problem related to some specific code snippet? Maybe a reference to a path? Is it related to MacOS?

Now that things work fine and the message is gone, is it possible to reproduce it without installing something new?

3 Answers 3

1

Due to security concern, Apple re-designed the file system beginning with High-Sierra version - see this or a little bit more detailed here - so in your settings you have an absolute path starting with the forbidden System.... and you must replace it with the permitted Users/yourname/.emacs.d or whatever you need.

As for errors in warnings window you see - just do package-refresh-contentsand try again to install the package you need.

2
  • Thanks, how exactly can I replace it? Could you give more instructions? Or a recommended material? Aug 4, 2022 at 14:47
  • 1
    Your locate-user-emacs-file should be "/Users/pedro/.emacs.d/custom-vars.el" - if it works for you in another hidden folder .dotfiles then ok, although Emacs recommend some special paths - see/search C-h I and choose the node Emacs and search for initialisation files/paths (not easy to write exactly where it is).
    – Ian
    Aug 5, 2022 at 8:35
1

Ian's and Pedro's propositions seem to do the job, but, IMHO, it's very strange to put this in your init file:

(setq custom-file (locate-user-emacs-file "/home/pedro/.dotfiles/.emacs.d/custom-vars.el"))

since locate-user-emacs-file is supposed to take as argument a file name, not a file path, and has a (not so simple) strategy to find it in the user-emacs-directory (cf. "files.el").

I would rather adapt the user-emacs-directory to the current environment.

Note that the following code could be the same on a macos- or on a linux-based machine.

Since, by default, user-emacs-directory contains "~/.emacs.d", I would change it like this:

(when (file-directory-p "~/.dotfiles")
  (setq user-emacs-directory "~/.dotfiles/.emacs.d"))

And then, you could change the name of your custom file like this:

(setq custom-file (locate-user-emacs-file "custom-vars.el"))

Note that, IMHO, the test with file-directory-p is more robust than the test of the system-configuration:

(setq user-emacs-directory
  (cond
   ((string-match "apple" system-configuration)
    "~/.emacs.d")
   ((string-match "NixOS or whatever ???" system-configuration)
    "~/.dotfiles/.emacs.d")
   (t "~/.emacs.d")))

since a macos computer could actually have a "~/.dotfiles" directory (as a matter of fact, my macs have had a "~/DOT_DIRS" directory since a few decades!)

0

@Ian was right.

Just to make it even easier for other people to understand it I will post another answer.

This problem originated from the process of bringing an Emacs init file from an old machine (running Linux-based NixOS and with .dotfiles being used) to a new macOS machine (which does not use .dotfiles on the file hierarchy).

Thus, changing my init file from:

(setq custom-file (locate-user-emacs-file "/home/pedro/.dotfiles/.emacs.d/custom-vars.el"))

To:

(setq custom-file (locate-user-emacs-file "/Users/pedro/.emacs.d/custom-vars.el")) 

Solved the problem on the new macOS machine.

Also, I tweaked the config file to include comments about the problem:

;; Avoid custom variables from Emacs, since this is a handcrafted file
;; Move them to a different file. There is macOS and a nixOS version
;; macOS
(setq custom-file (locate-user-emacs-file "/Users/pedro/.emacs.d/custom-vars.el")) 
;; nixOS config
;;(setq custom-file (locate-user-emacs-file "/home/pedro/.dotfiles/.emacs.d/custom-vars.el"))

(load custom-file 'noerror 'nomessage)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.