Emacs - I cannot save buffer into file because of backup - emacs

I am using C-x C-s to save a change in a buffer to a file. I am getting the following in my minibuffer:
symbol's variable as value is void: “/home/alex/\.emacs_backups/”
I added .emacs_backups/ a couple of days ago and I altered my .emacs file to:
;; create a backup file directory
(defun make-backup-file-name (file)
(concat “/home/alex/.emacs_backups/” (file-name-nondirectory file) “~”))
This does not happen in every directory. In some directories I can save a buffer change to a file no problem.

You have "smart quotes" in your .emacs. Elisp uses ASCII doublequotes as string delimiters:
(defun make-backup-file-name (file)
(concat "/home/alex/.emacs_backups/" (file-name-nondirectory file) "~"))
I replaced “ and ” with "
After you edit your .emacs, you should evaluate this new function definition with C-x C-e, so that you'll be able to save it without getting an error.

Related

How to move to end of temporary buffer in emacs inside function

I am trying to write an emacs function that will run make in the current directory, change to another directory and run make link all while outputting the text to a new buffer called make-output (original, eh?). Once complete, I'd like to move to the end of the make-output buffer so that I can see whether the compile was successful. Here is what I've got currently:
(defun remake-libefp-interface()
"Will run make in the current directory, change to the NWChem src directory and relink the binary."
(interactive)
(defvar T_pwd (getenv "PWD"))
(defvar T_top (concat (getenv "NWCHEM_TOP") "/src"))
(defvar cmd (concat "make; cd " T_top "; make link;cd " T_pwd))
(with-output-to-temp-buffer "*make-output*"
(shell-command cmd "*make-output*")
(pop-to-buffer "*make-output*")
(end-of-buffer)))
This recompiles correctly, but dumps me at the beginninng of make-output. I have also tried replacing the (end-of-buffer) with (goto-char (point-max)), but this also left me at the beginning.
Move the pop-to-buffer and (goto-char (point-max)) outside the with-output-to-temp-buffer.

Emacs auto-save: Why are files not stored in the correct folder?

I looked in various places and finally came up with the following setup for 'auto-save' mode in Emacs:
(defvar my-auto-save-folder (concat "~/.emacs.d/auto-save")); folder for auto-saves
(setq auto-save-list-file-prefix "~/.emacs.d/auto-save/.saves-"); set prefix for auto-saves
(setq auto-save-file-name-transforms `((".*", my-auto-save-folder t))); location for all auto-save files
(setq tramp-auto-save-directory my-auto-save-folder); auto-save tramp files in local directory
After having this setup for some weeks, I visited ~/.emacs.d and found that the folder ~/.emacs.d/auto-save is empty, while ~/.emacs.d contained two auto-save files of the form #!home!<myusername>!<myfolder>!<myfile>. Why are the auto-save files not stored in ~/.emacs.d/auto-save? [the folder auto-save has rights 775, .emacs.d 700]
Your error is in:
(defvar my-auto-save-folder (concat "~/.emacs.d/auto-save")); folder for auto-saves
(the call to concat with a single argument is pointless, incidentally).
If the optional element UNIQUIFY is non-nil, the auto-save file name is
constructed by taking the directory part of the replaced file-name,
concatenated with the buffer file name with all directory separators
changed to `!' to prevent clashes.
Emacs identifies directory names by a trailing /, which means that "the directory part" of the path you've used is "~/.emacs.d/".
You want:
(defvar my-auto-save-folder "~/.emacs.d/auto-save/"); folder for auto-saves
The positioning of the comma in the following is also strange (although apparently it still works):
`((".*", my-auto-save-folder t)))
That should really be:
`((".*" ,my-auto-save-folder t)))
This is what i have in my .emacs, which works well for me:
(add-to-list 'auto-save-file-name-transforms
(list "\\(.+/\\)*\\(.*?\\)" (expand-file-name "\\2" my-auto-save-folder))
t)

change .emacs file's location

I am working on windows xp
I stored emacs in usb
I want to carry the .emacs file as well as binary files
what I tried are
(setenv “HOME” (format "%s" (getenv "emacspath")))
(setenv “HOME” (format "%s/" (getenv "emacspath")))
It seems works if I eval-expression in emacs
After setenv, I could notice setting env is works well by (getenv "home")
but I put the (setenv "home" (format "%s/" (getenv "emacspath")))
in "site-start.el" file in "site-lisp" folder, starting emacs says "Symbol's value as variable is void: "HOME"
Any ideas?
An easier way - just create a batch file on your USB drive where you can set all env variables you need. Then start emacs.exe from the batch.
For example if you want to run SBCL add the following lines to your batch
rem SBCL_HOME is required for SBCL
set SBCL_HOME=%utils%\Lisp\sbcl\1.0.29
set SBCL_RUN=%SBCL_HOME%\sbcl.exe
set SBCL_OPTIONS=--noinform
How about using default.el either as a symlink or as a simple elisp pinter to your file:
(load-file "/path/to/usb/.emacs")
Add following code to a file (e.g. c:/.emacs).
;; This function must be at begin
(defun zxy-relocate-dotemacs ()
"Relocate .emacs file"
(interactive)
(with-temp-buffer
(let (print-level print-length)
(insert (format "(load-file \"%s\")" load-file-name))
(if (file-exists-p "~/.emacs")
(message "[zxy] Don't need relocate .emacs file!")
(progn
(message "[zxy] Relocate .emacs file.")
(write-file "~/.emacs"))))))
(zxy-relocate-dotemacs)
;; Your configuration here
Open emacs and M-x load-file c:/.emacs.
Then it will relocate .emacs to c:/.emacs.
I use this when I copy my emacs to a new computer.
More information please visit my blog abuot emacs.
http://coordinate.sinaapp.com/?cat=3

Erlang emacs mode - setting outdir

Does anyone know how to configure Erlang emacs mode so that compiling a buffer [C-c C-k] writes the beam file to the ebin directory rather than the current directory ?
Thanks!
You might want to have a look to this thread on the Erlang Questions Mailing List:
http://www.erlang.org/pipermail/erlang-questions/2007-August/028367.html
Moreover, you should be able to compile your file in debug mode:
C-u C-c C-k
The erlang-compile command should support prefix arguments. You might want to have a look to:
http://www.gnu.org/software/emacs/manual/html_node/elisp/Prefix-Command-Arguments.html
If you set up your directory structure like so:
/
/src/
/ebin/
and place your module (e.g. "my_file.erl") in the "/src/" directory then compile it (C-c C-k) then Emacs should automatically put the beam into the "/ebin/" directory.
However, if your module isn't in a directory named "/src/" (or if the "ebin" directory is missing) the beam will be dropped alongside the source file.
To see exactly how this works take a peek at $ERL_TOP/lib/tools/emacs/erlang.el and search for "ebin". Here's what you'll find:
(defun inferior-erlang-compile-outdir ()
"Return the directory to compile the current buffer into."
(let* ((buffer-dir (directory-file-name
(file-name-directory (buffer-file-name))))
(parent-dir (directory-file-name
(file-name-directory buffer-dir)))
(ebin-dir (concat (file-name-as-directory parent-dir) "ebin"))
(buffer-dir-base-name (file-name-nondirectory
(expand-file-name
(concat (file-name-as-directory buffer-dir)
".")))))
(if (and (string= buffer-dir-base-name "src")
(file-directory-p ebin-dir))
(file-name-as-directory ebin-dir)
(file-name-as-directory buffer-dir))))
Not sure when this goody was added, but it was in OTP_R13B03 and it works for me in R14B03.

How do I uncompress/unzip within Emacs

I would like to run unzip (or even zip) within dired or a dired-like buffer. Is there anything like this? I would like something similar as in the Nautilus file manager: i.e., selecting files and then pressing a keystroke to get these files into a new archive file.
Thank you
You've got options...
To uncompress a .zip file, you just need to add to the variable 'dired-compress-file-suffixes
(eval-after-load "dired-aux"
'(add-to-list 'dired-compress-file-suffixes
'("\\.zip\\'" ".zip" "unzip")))
Now the Z key in dired will recognize the .zip extension and uncompress a .zip archive. Already supported are gunzip, bunzip2, uncompress and dictunzip.
If you want to mark files and add them to a .zip archive you can use the following to make z bound to zip the set of marked files:
(eval-after-load "dired"
'(define-key dired-mode-map "z" 'dired-zip-files))
(defun dired-zip-files (zip-file)
"Create an archive containing the marked files."
(interactive "sEnter name of zip file: ")
;; create the zip file
(let ((zip-file (if (string-match ".zip$" zip-file) zip-file (concat zip-file ".zip"))))
(shell-command
(concat "zip "
zip-file
" "
(concat-string-list
(mapcar
'(lambda (filename)
(file-name-nondirectory filename))
(dired-get-marked-files))))))
(revert-buffer)
;; remove the mark on all the files "*" to " "
;; (dired-change-marks 42 ?\040)
;; mark zip file
;; (dired-mark-files-regexp (filename-to-regexp zip-file))
)
(defun concat-string-list (list)
"Return a string which is a concatenation of all elements of the list separated by spaces"
(mapconcat '(lambda (obj) (format "%s" obj)) list " "))
To zip files, open the directory in dired. Mark the files you want to zip with m. Then type
! zip foo.zip * <RET>
To extract an entire archive from dired you can mark a file and run & unzip, just as you would in a shell.
zip-archive mode will allow you to browse zip files in a dired-like fashion. It should come with recent versions of GNU emacs and will be used by default when you visit a file with the .zip extension. From this mode you can extract individual files into a buffer, and from there save them with C-x C-s.