jennifer@mead.UUCP (Jennifer Lill) (07/20/90)
How can I search for a string containing a non-printable that emacs would display with a \<hex-value>? Jennifer
mcgrath@homer.Berkeley.EDU (Roland McGrath) (07/21/90)
In article <929@meaddata.mead.UUCP> jennifer@mead.UUCP (Jennifer Lill) writes: > How can I search for a string containing a non-printable that emacs would > display with a \<hex-value>? The values are octal, not hexadecimal. You can enter any character in octal at any time bu doing C-q NNN where NNN is the octal value. If you are doing a normal i-search, for "foo\001bar", do C-s f o o C-q 0 0 1 b a r. You can also enter control characters that would otherwise be commands by preceding them with C-q, so you could do the above as: C-s f o o C-q C-a b a r -- Roland McGrath Free Software Foundation, Inc. roland@ai.mit.edu, uunet!ai.mit.edu!roland
shapiro@athos.rutgers.edu (Joel Shapiro) (07/22/90)
I don't think mcgrath answered the question, at least not my question, which is How can you pass through a file checking for the existence of any control characters that might screw up printing? and does anyone have an .el file which will convert all such characters to some printable representation (for example, so they will print the way they appear on the screen) Joel Shapiro
mcgrath@tully.Berkeley.EDU (Roland McGrath) (07/24/90)
In article <Jul.22.09.46.19.1990.21055@athos.rutgers.edu> shapiro@athos.rutgers.edu (Joel Shapiro) writes:
I don't think mcgrath answered the question, at least not my question,
which is
How can you pass through a file checking for the existence of any
control characters that might screw up printing?
and does anyone have an .el file which will convert all such
characters to some printable representation (for example, so they will
print the way they appear on the screen)
Joel Shapiro
I answered the question asked in the posting I was responding to.
Since I don't know what characters will screw up printing for you, I cannot
necessarily answer your question to your satisfaction. However, if it is
assumed that all non-printing characters other than TAB, LF, SPC, RET, and FF are problematical, I can offer this:
A regular expression for searching for such characters is (in a Lisp string):
"[\^@-\^h\^k\^n-\^_\177-\377]". The following function will turn such
characters into their printing representations:
(defun printify-buffer ()
"Turn nonprinting characters in the current buffer
into their printable representations."
(interactive)
(save-excursion
(goto-char (point-min))
(let (c)
(while (re-search-forward "[\^@-\^h\^k\^n-\^_\177-\377]" nil t)
(setq c (char-after (point)))
(delete-char 1)
(insert (if (and (>= c ?\^@) (<= c ?\^_))
(format "^%c" (- c ?@)))
(format "\\%03o" c))))))
--
Roland McGrath
Free Software Foundation, Inc.
roland@ai.mit.edu, uunet!ai.mit.edu!roland
deschamp@minos.inria.fr (Philippe Deschamp) (07/24/90)
In article <929@meaddata.mead.UUCP>, jennifer@mead.UUCP (Jennifer Lill) writes: |> How can I search for a string containing a non-printable that |> emacs would display with a \<hex-value>? I use "isearch-forward-regexp" (bound to M-^S) with the appropriate regexp: "[^^@-~]" to find characters with the 8th bit on (your question as I understand it), "[^^I^J -~]" to find non-printable characters (what I usually do). As these regular expressions are fed interactively to Emacs, you need some care to type them. The first regexp is obtained by typing the sequence [ ^ C-q C-@ - ~ ] and the second one by [ ^ TAB RET SPC - ~ ] Of course, this only works for ASCII... Philippe Deschamp. Tlx: 697033F Fax: +33 (1) 39-63-53-30 Tel: +33 (1) 39-63-58-58 Email: deschamp@seti.inria.fr || ...!inria!deschamp Smail: INRIA, Rocquencourt, BP 105, 78153 Le Chesnay Cedex, France