Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6552603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:28:46+00:00 2026-05-25T12:28:46+00:00

I ran into something a bit weird with the hexl-mode under Emacs (GNU Emacs

  • 0

I ran into something a bit weird with the hexl-mode under Emacs (GNU Emacs 22.2.1 / Debian GNU Linux).

I had an UTF8 text file to which I wanted to append a BOM (Byte Order Mask: even though it is not recommended to append a pointless BOM to an UTF8 file, the spec clearly specify that a BOM in an UTF8 file is legal).

Here’s how the file is seen by the file command:

...$  file  /tmp/test.txt
/tmp/test.txt: UTF-8 Unicode English text

The following works:

open the UTF8 file (without BOM) in text mode
add three ASCII characters at the beginning of the file
close the file   (<-- see, very important, I need to close the file)
M-x hexl-mode
M-x hexl-find-file  (re-opening the file but this time in hexl-mode)
M-x hexl-insert-hex-string
EFBBBF
C-x C-s (saving the file)
M-x hexl-mode-exit

I then get an UTF-8 file with a BOM, as shown here by the file command:

...$  file  /tmp/test.txt
/tmp/test.txt: UTF-8 Unicode (with BOM) English text

(note that the file command detects this heuristically as an UTF-8 with BOM “English text” but the file does contain a lot of Euro symbol: my point is that, before adding the BOM, it is NOT an ASCII file but already an UTF-8 file, as shown above)

However I simply cannot open the file under Emacs first then call hexl-mode then try to replace the first three characters by 0xEB 0xFF 0xBF (the BOM) and then save.

Apparently there are crazy conversion issues taking place when switching from (Text) to (Hexl) mode.

Am I missing something obvious or is converting to/from Text / Hexl a bit broken and I’m better to switch to hexl-mode first, do my hex editing then save & close the file and re-open in text mode?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:28:47+00:00Added an answer on May 25, 2026 at 12:28 pm

    If you take a look on hexl-find-file code you will see that it calls find-file-literally and then switch to the hexl-mode.

    From the documentation of find-file-literally

    Visit file FILENAME with no conversion of any kind. Format conversion
    and character code conversion are both disabled,and multibyte
    characters are disabled in the resulting buffer.

    So you may open your file with find-file-literally add 3 characters and then switch to the hexl-mode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just ran into something weird. I have two JSON arrays which holds different
I've been working on my richtextbox but I ran into something weird... I want
Ran into something interesting, want to know if I'm doing something wrong or if
I ran into something a little odd this morning and thought I'd submit it
I ran into something odd, and I'm not precisely sure why it is behaving
I just ran into something in Visual Studio 2010 RC that wasn't previously happening
I was doing some performance metrics and I ran into something that seems quite
I just started playing around with threading today and I ran into something that
I ran into an issue with something that I am probably just overlooking. I
This originally was a problem I ran into at work, but is now something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.