Hide latex (auctex) output buffer - emacs

When I compile a (Xe)LaTeX file, emacs writes the output to the LaTeX output buffer and shows it. For pure LaTeX, this buffer is hidden.
How do I hide a Latex compilation buffer?

Forget it, there is this (setq TeX-show-compilation t) in the script I was using, so I just set it to nil.

Related

Emacs+AucTex: can't display the output window when the reftex-toc window is dedicated

I am edting latex files with Emacs+AucTeX. When working I have two windows in the frame: the latex file window and the reftex-toc window. I set the reftex-toc window dedicated to its buffer by
(defadvice reftex-toc (after reftex-toc-window-dedicated activate)
(set-window-dedicated-p (selected-window) t))
to keep it from being replaced.
But problems arise when I call (TeX-recenter-output-buffer) by C-c C-l. The output buffer can't be displayed. I have to manually switch to the output buffer by C-x b. And if I call help commands, e.g. C-h f, the help buffer is not displayed in a new window as it should be. Instead, it replaces the latex file window. How can I fix this problem?
EDIT
I found that the problem is due to function (display-buffer BUFFER), which is internally called by (TeX-recenter-output-buffer). Under normal circumstances where there is no dedicated window in the frame, (display-buffer BUFFER) creates a new window for BUFFER. But if there are a dedicated window and some normal windows, (display-buffer BUFFER) just displays BUFFER in one of the normal windows w/o creating a new one.
As a workaround, I open another (the 3rd) window, so that if I call C-c C-l, the compilation output is displayed there and the latex file window is kept. However, I am still looking forward to a real solution. Could any one help? Thank you.

in org-mode, how to instruct save-some-buffers to ignore Agenda buffers?

In Emacs org-mode, I use the command save-some-buffers as a default save command to save all the buffers I've been working with. How do I instruct Emacs to not prompt me to save my Calendar and Org Agenda buffers?
If these are file buffers, then you can tell Emacs to save them without prompting by setting buffer-save-without-query (of course, you only want to set it buffer-locally in those buffers). And if these aren't file buffers, then Emacs prompts you only if buffer-offer-save is non-nil in that buffer, so you can avoid the prompt by setting that variable back to its nil default (in which case it won't save those buffers for you).

Auto-formatting a source file in emacs

How do I apply a set of formatting rules to an existing source file in emacs?
Specifically I have an assembly (*.s) file, but I would like a generic command for all types of files.
I am trying to use M-x c-set-style with gnu style, but I am getting an error:
Buffer *.s is not a CC Mode buffer (c-set-style)
Open the file and then indent it by indenting the entire region:
M-x find-file /path/to/file RET
C-x h (M-x mark-whole-buffer)
C-M-\ (M-x indent-region)
Now, it looks like you're trying to apply C indentation to a buffer that's not in C mode. To get it into C mode
M-x c-mode
Or c++-mode, or whatever mode you want. But, since it's assembler code, you probably want assembler mode (which Emacs will do by default for .s files). In which case, the indentation command above (C-M-\ is also known as M-x indent-region) should work for you.
Note: the command sequence at the top can be rolled into a single command like this:
(defun indent-file (file)
"prompt for a file and indent it according to its major mode"
(interactive "fWhich file do you want to indent: ")
(find-file file)
;; uncomment the next line to force the buffer into a c-mode
;; (c-mode)
(indent-region (point-min) (point-max)))
And, if you want to learn how to associate major-modes with files based on extensions, check out the documentation for auto-mode-alist. To be fair, it's not necessarily extension based, just regular expressions matched against the filename.
Try M-x asm-mode. That will switch to assembler mode. Not sure how it will go with assembler embedded in the middle of a C file.
if you want indent current buffer
(defun iwb ()
"indent whole buffer"
(interactive)
(delete-trailing-whitespace)
(indent-region (point-min) (point-max) nil)
(untabify (point-min) (point-max)))
emacs will use the file name extension to identify the mode, you should add some assemble language mode style in your custom.el file
The major mode it's using for your .s files won't be cc-mode hence c-set-style makes no sense. However you can always manually enter cc-mode (M-x cc-mode) and then do the c-set-style you want. However as the C styles are keyed for C source code and not assembler this is almost certainly not what you want to do.
if you want to indent from the command line use :
emacs --batch <filenames.v> -f verilog-batch-indent

Using Emacs, how could I indent/format a code segment in a TXT file?

I am writing a document with Emacs. As you know, there are some code segments in the text file I am working with. Typically, when I open this file, emacs will get into text-mode automatically. And it works fine for me to edit the ordinary paragraphs. But for those code segments, how could I indent them into gnu or linux style just like what I could do in c-mode (by c-set-style && do Ctrl-Alt-\ in certain region)?
BTW, actually, I could turn the buffer into c-mode by invoking M-x c-mode to do this, however, I think there should be much a graceful way to do this in text-mode.
orgmode manages to do it by copying the code out to a temporary buffer where you edit & format it, and updating the changed text when you're done.
If switching to orgmode is an option, then you do it like this:
#+BEGIN_SRC emacs-lisp
(defun org-xor (a b)
"Exclusive or."
(if a (not b) b))
#+END_SRC
and start and finish editing with C-c '.
Edit: Emacswiki has a list of multiple modes.
You might be able to mark the region, then narrow the view to the region, change the mode, indent, return to text-mode, and return to the full buffer again. I forget the exact shortcuts at the moment, but it should be fairly easy to turn into a function.

How can I apply a new Emacs C style to reformat all my source files?

I'd like to re-format all my source files using the Google formatting function for emacs: google-c-style.el (see here).
How can I apply this function to all my source files at once, so that they are all formatted and indented correctly according to the Google style?
There are several pieces to this:
you need to come up with EMACS functions to do all the reformatting you want. indent-region is a start, but you might also want to untabify or some other things.
you need to invoke them on each file, and since the indent functions work on ranges, you need a function that sets mark to cover the whole file: mark-whole-buffer.
you need to invoke EMACS on each file: this means invoking emacs with the --batch file.
There's a couple of nice blog posts on doing this here and here.
I have done this before by using a keyboard defined macro. I would load all of the files into emacs (something like find . -name "*.cpp" | xargs emacs) and then type the following keys. I've annotated each key combination with what it does.
C-x-( 'Begin recording macro
M-< 'Go to start of file
C-space 'Mark current location (now start of file)
M-> 'Go to end of file
M-x indent-region 'Indent entire file according to coding style
C-x C-s 'Save the current buffer
C-x C-k 'Close the current buffer
C-x-) 'End recording macro
Now you can run this on a buffer by typing C-x e. If you have loaded several files you can run something like C-u 100 C-x e to run this on 100 files. If this is more than the number of files, that is ok, you'll just get some "bell ring" or other error you can ignore once all the processing is complete.
I believe that this script does not do reformatting. Instead it's an example of how to build a custom "style" as described in: CC mode manual - Styles
CC-mode manual also says:
If you want to reformat old code, you're probably better off using some other tool instead, e.g. GNU indent, which has more powerful reformatting capabilities than CC Mode.
CC mode manual - Limitations-and-Known-Bugs
If you want to mark the source files in a dired buffer and then run a function to format each you can do something like this:
(defun clean-file(filename)
(your-function-goes-here))
(defun clean-each-dired-marked-file()
(interactive)
(for-each-dired-marked-file 'clean-file))
(defun for-each-dired-marked-file(fn)
"Do stuff for each marked file, only works in dired window"
(interactive)
(if (eq major-mode 'dired-mode)
(let ((filenames (dired-get-marked-files)))
(mapcar fn filenames))
(error (format "Not a Dired buffer \(%s\)" major-mode))))