4

I found emacs cannot save the macOS tag when the file changed and save from buffer

macOS tag

I create a empty file with macOS tag

create a empty file with macOS tag

and use emacs to open it and write something

use C-x C-s to save and the tags in Finder disappeared

after save

How could I have a method to reserve these tags when I resave it?

  • I cannot imagine that the vanilla Emacs development team has invented a way to deal with MacOS file tags. This is the first time that I've even heard of system file tags, probably because I still use OSX 10.6.8 at home and El Capitan when on the road. Most likely, you will need to submit a feature request to the main development team. In the alternative, there is a modified version of Emacs called Mac Port (Yamamoto Mitsuharu) that has system specific features / enhancements -- it may be worthwhile to submit a feature request to them also. – lawlist May 2 '18 at 14:35
  • I'm not able to reproduce this behavior with Emacs 25.3.1 on El Capitan (Mac OS 10.11.6). If I add a tag to a file and edit it in Emacs the tags persist – matteol May 4 '18 at 17:22
  • Tags are stored as extended file attributes, under com.apple.metadata:_kMDItemUserTags. But file-extended-attributes doesn't know them. – Andrew Swann May 7 '18 at 7:26
2

I don't know how the tags are implemented but if they are associated to the inode and not to the name you can try to set the variable backup-by-copying to t.

When emacs creates a backup normally renames the old file and create a new one with the new content (see the documentation), when backup-by-copying is t it copies the old file to create a backup and writes the new content in the old one.

  • I use open(2) to change a file and the tag don't disappear. I don't know how does emacs implement saving file. – Li Hanyuan May 4 '18 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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