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, 2018 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, 2018 at 17:22
  • Tags are stored as extended file attributes, under com.apple.metadata:_kMDItemUserTags. But file-extended-attributes doesn't know them. May 7, 2018 at 7:26

1 Answer 1


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, 2018 at 15:58
  • Can confirm that backup-by-copying works for this as "advertised". Thanks for the tip!
    – halloleo
    Nov 15, 2019 at 3:33

Your Answer

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

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