How to open ".z" file in emacs? - emacs

I have a plaintext file named ~/.z but when I open it with emacs --no-init-file, I get a blank buffer and a buffer named *jka-compr-error* which states
Error while executing "gzip -c -q -d < /home/username/.z"
gzip: stdin: not in gzip format
How can I open this file in emacs?

Use find-file-literally. It does no conversions and it does not use the auto-mode-alist to set the major mode: it uses fundamental-mode instead.

Turn off auto-compression-mode in your .emacs file: (auto-compression-mode 0), and try again.

.z is an unix compression file extension.
So probably you cant open it. But you can always extract it but i think extracting would not be the case here since you said thats a plaintext file.

Related

How to get vim to list the PIDs of selected files that are presently being edited, avoiding recovery mode, and not list all the other files

The vim manual page contains two similar -r type commands. I'll give more background below, this question is really how to invoke the first type of -r to list the swap files, but avoid the second -r that invokes recovery
-r List swap files, with information about using them for re‐
covery.
-r {file} Recovery mode. The swap file is used to recover a crashed
editing session. The swap file is a file with the same
filename as the text file with ".swp" appended. See ":help
recovery".
The -r without filename (the first -r above ) reports on the swap files of other files too, including ones in other directories
Background:
I'm trying to have vim report the swap files of a specific file (mostly to determine if vim still editing the file). If the file is being edited ( in another window, either on linux or cygwin ) I can 'raise' that window up to the top with "\e[2t\e[1t" as I have successfully be able to do thanks to Bring Window to Front
Vim has multiple swap file names, and multiple directories that it could put a file, so I want to ask vim, please tell me the name of the swap files that are currently in use for a given file, and if there is a current vim process on the file. Unfortunately, sometimes vim will open a command file in recovery mode in unexpected ways.
I'm invoking vim like this vim -r -c :q file, well actually, I'm invoking it from script, since I want vim to see something more like a terminal, then I look at the output file, so it's more like script -q -c "vim -r -c :q foo" fooscript, then I look in the fooscript file for messages like /Note: process STILL RUNNING: (\d+)/
It is beginning to look like I need to use vim -r without a file name, and parse the output of the -r report, and that there isn't a way to get the report pre-filtered to a single file in question.
after switching my focus to just vim -r, and
Knowing that vim will try to put the swap file into the same directory as the file it's editing ( thanks to #romainl for the pointer to :help swap-file )
observing that vim -r reports on the files in the current directory first,
observing that the file name associated with the swap file is reported before the process id of the vim process, and
observing that vim appends (STILL RUNNING) if it finds the active process
I changed the current directory appropriately and ran this code after plugging in the name of the file-to-search-for
perl -lne '
last if /^\s+In directory/;
undef $f if /^\d+/;
$f = $1 if /^\s+file name:\s+(.*)\s*$/;
if ( $f =~ m#/file-to-search-for# && /^\s+ process ID:\s(\d+).*?STILL RUNNING/ ) {
print $1;
$pid //= $1;
}
END { exit !$pid; } '
The pid of the running vim process is printed, and the exit status is zero when the appropiate swap file is found, and non-zero if the file was not being edited

Perl command to change file EOL and saving the file with the same name

I am using this perl command on my debian to change my file EOL:
perl -p -e 's/\n/\r\n/' < ~/scripts/bite/EOL/*.csv > ~/scripts/bite/sent/samefilename.csv
Every day there will be a new file in the "EOL" directory with a different name and it always has only 1 file in the directory, so I am using "*" to take whatever file is in it.
But i need to save the new file with the same name as the file I chose to change without manually entering the file name to the command. Eventually this goes into my cronjob, so everything would be automatic.
EDIT: Fixed my problem by using "unix2dos"
Linux has command unix2dos and dos2unix for converting eol from MS Windows/DOS to UNIX format. Perhaps it is easiest solution for described problem.
unix2dos
dos2unix
I would use the unix2dos utility, but you can also use
perl -pe's/\n/\r\n/' -i file.csv
See Specifying file to process to Perl one-liner.
Your program and this one only works on unix systems.

How do I specify output file for running emacs in batch mode?

I am running emacs with Verilog-mode in batch mode. Normally, it overwrites the source file, but I would like to preserve the source file and write the output to a different file. I am trying to put this into a makefile flow, so I need separate input and output files.
My command line:
emacs --batch xyz.auto.sv -f verilog-diff-auto
Try
emacs --batch xyz.auto.sv -f verilog-diff-auto --eval '(write-file "output.sv")'
That should read the input file into a buffer, do whatever verilog-diff-auto is supposed to do and then save the modified buffer to the output file.

Add text to the top of multiple files in emacs

I'd like to add a couple lines of text (copyright) to the top of all text files in a directory. Can I do this in emacs without copy/pasting for each file?
This is copied from Chris Conway's answer to a different question: Using Emacs to recursively find and replace in text files not already open
M-x find-name-dired: you will be prompted for a root directory and a filename pattern.
Press t to "toggle mark" for all files found.
Press Q for "Query-Replace in Files...": you will be prompted for query/substitution regexps.
Proceed as with query-replace-regexp: SPACE to replace and move to next match, n to skip a match, etc.
You can use it the same way
Yes, with
find . -type f -exec emacs -batch '{}' --eval '(insert-string "foo\nbar\nbaz\n")' -f save-buffer \;
or something to that effect. The emacs bit is
emacs -batch filename --eval '(insert-string "foo\nbar\nbaz\n")' -f save-buffer
replace "foo\nbar\nbaz" with your message. However, using emacs for this is really a lot of overkill. You could just put your copyright header into a file and use cat header file > tempfile; mv tempfile file.

Emacs opening and saving encoding

I have a Perl source file in utf-8 encoding, LF ending. It contains English and Chinese characters. The questions are:
1.When I open file, the encoding is windows-1251-unix. I have to run these commands:
Alt-x revert-buffer-with-coding-system
> Coding system for visited file (default nil):
utf-8-auto-unix
> Revert buffer from file file_name.pl?
y
How to automatically open it in utf-8-auto-unix?
2.When I edit the file and try to save it, Emacs gives me a question:
> Select coding system (default raw-text):
utf-8-auto-unix
How to automatically save the file in utf-8-auto-unix? And get rid of the question.
You could add this comment to the top of the file:
# -*- coding: utf-8 -*-
Use describe-variable(C-h v) to examine the variable current-language-environment; follow the customize link and set it to "UTF-8".