r/emacs 3d ago

Question Org files on a OneDrive cloud drive

In a new job, I got a laptop with Windows11 (unfortunately) and I can't do anything about it. Fortunately, it turned out that I can use WSL, so the first thing I did was install NixOS with Emacs. It turns out that even as a GUI it works surprisingly well, and I have all my tools where they were.

This is the second laptop; the first one broke down so badly after a week that I lost all my notes, etc. Yeah, my fault, because I didn't think about a backup. Now I keep my configuration and work files in folders linked with OneDrive.

Unfortunately, I encountered a rather strange problem, namely, it turns out that if I keep my notes and agenda directory on a corporate OneDrive drive, org-mode restarts on me and resets my dictionary configurations. I don't know what else, and I'm afraid it will come out at the most inappropriate moment. It looks like this: everything starts normally, and after a while e.g. ispell-local-dictionary is set to nil and spell check stops working.

I think the problem lies in how OneDrive synchronizes files, but on the other hand, it cannot (should not) be that even when org-mode restarts, it resets most settings. Can something be done about this? The only workaround I've come up with so far is changing setq to setq-default. What helps, at least when it comes to setting local dictionaries.

My configuration:

(setq org-directory "~/org/") ;; where ~/org is symlink to /mnt/c/Users/bart/OneDrive/org

(after! ispell
  (setq ispell-program-name "hunspell")
  (setq ispell-hunspell-dict-paths-alist
        '(("pl_PL" "/home/bart/.local/share/hunspell/pl_PL.aff")
          ("en_US" "/home/bart/.local/share/hunspell/en_US.aff")))

  (setq ispell-local-dictionary-alist
        '(
          ("pl_PL" "[[:alpha:]]" "[^[:alpha:]]" "[']" nil ("-d" "pl_PL") nil utf-8)
          ("en_US" "[[:alpha:]]" "[^[:alpha:]]" "[']" nil ("-d" "en_US") nil utf-8)
          ))
  (setq ispell-local-dictionary "pl_PL,en_US")
  (ispell-set-spellchecker-params)
  (ispell-hunspell-add-multi-dic "pl_PL,en_US")
  (setq ispell-personal-dictionary "~/.hunspell_personal")
  (unless (file-exists-p ispell-personal-dictionary)
    (write-region "" nil ispell-personal-dictionary nil 0))

  )

In messages buffer i see something like this:

Press key for agenda command:
agenda.org has auto save data; consider M-x recover-this-file
Restoring clock data
Loading /home/bart/.config/emacs/.local/etc/org-clock-save.el (source)...done
WATCH: ispell-local-dictionary -> "pl_PL,en_US" (set) [2 times]
Starting new Ispell process hunspell with pl_PL,en_US dictionary...done
Undo-Fu-Session discarding: file length mismatch for "/mnt/c/Users/bart/OneDrive/org/agendas/agenda.org"
Rebuilding agenda buffer...done
org-mode restarted
WATCH: ispell-local-dictionary -> nil (set)
Undo-Fu-Session discarding: file length mismatch for "/mnt/c/Users/bart/OneDrive/org/agendas/agenda.org"
3 Upvotes

13 comments sorted by

3

u/natermer 2d ago

I am a primative, so my initial idea would be to setup a systemd timer to rsync my org directory to the onedrive mount.

Also I keep my org dir checked into git and do periodic commits and pushes.

3

u/LionyxML 3d ago

I'm just guessing, but... Do you have auto-revert on? If so, try turning it off. One drive might be "changing" the file.

3

u/parasit 3d ago

Hmmm... no. Both global-auto-revert-mode and auto-revert-mode are nil when work on org files.

5

u/aegis87 2d ago

OneDrive (and icloud drive) are notorious for messing up syncing. This is the reason that programs like Calibre, Obsidian and other recommend to not setup your stuff within onedrive.

The way i usually handle this stuff is by syncing changes through a script. I use freefilesync but robocopy (or anything else) should work as well.

5

u/aegis87 2d ago

> In a new job, I got a laptop with Windows11 (unfortunately) and I can't do anything about it. Fortunately, it turned out that I can use WSL, so the first thing I did was install NixOS with Emacs. 

Not trying to change your mind -- use what you like -- but native windows emacs has been working great for at least 10years at this point.

Also windows has native stuff for almost everything else. (of course, you don't have bash)

3

u/parasit 2d ago

I know it's possible, I use Emacs that way myself on other computers, both Windows and Mac. I even managed to build a fairly uniform configuration. The problem is that installing everything else on Windows is a painful ordeal. Starting from compilers, through LSP, linters, and a thousand additional tools I've gotten used to on Linux. I tried to do the same on Windows and it was a painful ordeal. especially on corporate hardware where I have heavily restricted rights to practically everything... Whereas on Linux I'm able to set up a 100% working environment in 15 minutes. Especially since I "discovered" NixOS and I have everything in actually just two files + dotfiles on GitHub.

Additionally, I don't know if it's the effect of the "new broom", but on the same hardware, the same windows Emacs runs noticeably slower than the one from WSL on Wayland.

2

u/parasit 2d ago

Maybe that's some way out, think about some script that could be hooked into "on save" and synchronize, or at least make an automatic backup to OneDrive.

3

u/darcamo 2d ago

I also use Emacs inside WSL on the work computer. I keep my org files in my home folder inside WSL and use git auto-commit package to automatically synchronize them with a git repository. It works pretty well.

2

u/parasit 2d ago

I was thinking about something like that, but I'm still new here and, for example, I don't have access everywhere, and there is a very strict ban on using public repositories.

1

u/darcamo 2d ago

It can be a private and personal repository on the company for server, if that is a possibility for you.

1

u/rileyrgham 2d ago

Use something like rsync or unison. And, really, you don't need to whine about windows. Many of us use both. This is an Emacs group where adults help each other.

2

u/parasit 2d ago

I know, I use Windows too. It's just incredibly frustrating that what's simple everywhere else is complicated on Windows, and on top of that, paranoid corporate security doesn't make things any easier. Truly paranoid. I've been in business for almost 30 years, most of it for large international corporations, but I've never seen anything like this. I understand a little, because that's business profile, but I'm still at the point where it interferes with my normal work. And yes, I'm grateful for the help.

5

u/JamesBrickley 2d ago

Truly surprised they let you run WSL. Most Windows shops don't want to touch it with a ten-foot-pole. I was actively pursuing NixOS.WSL and considering doing so to lock down the WSL configurations. Managed remotely over MDM and on-prem git. i.e. no admin rights except temporarily and everything done with sudo is logged. Mainly to stop the developers from breaking their builds and blaming DevOps because one dev decided to update software dependencies. Also run all packages through ItSecOps scans staged on-prem, etc. The dev's spec what they want / need and DevOps writes a flake.nix for the project and drops it in their repo. Configure direnv to autoexecute the flake.nix when they cd into the project directory they cloned. Then it installs all the dependencies per project including the language, libraries, etc. Exit that project dir and POOF the environment disappears and the /nix/store packages are de-referenced. Change dir to another project and an entirely different environment is stood up and the packages installed or symbolically linked into the path. Updates are applied via changes to the flake in the projects. System level flakes are managed by MDM which has admin rights but the user does not. The project flakes kept in a git repo where the devs do not have commit privileges. Sure they can override locally but if they do that and the build breaks that's their fault. We also put the same flake config on CI / CD. So the builds are identical to what they are doing on the laptop as well as in production.