How to setup emacs so that I can browse through previous-compilation errors during new compilation?
Two things don't work for me:
M-g M-g (next-error) function is not working when second compilation is in-progress.
I have my emacs split into 5 uneven windows (split-windows-horizontally), the compilation "window" is double the size (dbl monitor setup). When I launch compilation it always appeared in the last double compilation window. Now it opens a new window for itself.
Here is a solution which seems to fulfill all your requirements:
the *compilation-old* buffer always stays in the same window
next-error does not break
all successive compilation outputs are appended at the end of *compilation-old* when the compilation process terminates
(defun my-compilation-finish-function (buffer msg)
;; Don't do anything if we are in a derived mode
(when (with-current-buffer buffer (eq major-mode 'compilation-mode))
;; Insert the last compilation output at the end of *compilation-old*
(if (get-buffer "*compilation-old*")
(with-current-buffer "*compilation-old*"
(save-excursion
(goto-char (point-max))
(insert-buffer buffer)))
(with-current-buffer buffer
(rename-buffer "*compilation-old*")))))
(add-hook 'compilation-finish-functions 'my-compilation-finish-function)
(defadvice compile (around my-compile-show-old activate)
"Show the *compilation-old* buffer after starting the compilation"
(let ((buffer (current-buffer)))
(when (get-buffer "*compilation-old*")
(pop-to-buffer "*compilation-old*")
(switch-to-buffer "*compilation*"))
ad-do-it
(when (get-buffer "*compilation-old*")
(switch-to-buffer "*compilation-old*")
(pop-to-buffer buffer))))
Putting the following in your init file will rename the compilation buffer to *compilation-old* when the compile command terminates.
Please note that this will not work if you run the new compilation process from the old compilation buffer (since compile will in this case reuse the buffer instead of creating a new one)
(defun my-rename-compilation-buffer (buffer message)
;; Don't do anything if we are in a derived mode
(when (with-current-buffer buffer (eq major-mode 'compilation-mode))
(let* ((old-compilation-buffer-name "*compilation-old*")
(old-compilation-buffer (get-buffer old-compilation-buffer-name)))
;; Kill old compilation buffer if necessary
(when old-compilation-buffer
(kill-buffer old-compilation-buffer))
;; Rename the current compilation buffer
(with-current-buffer buffer
(rename-buffer old-compilation-buffer-name)))))
(add-hook 'compilation-finish-functions 'my-rename-compilation-buffer)
It's a bit of a Kludge, but try this:
Before starting the new compilation, save (write, C-x C-w) the current compilation buffer to a file. If the buffer for the new file looses it "compilation-mode" setting, simply turn compilation-mode back on (M-x compilation-mode).
Related
I am trying to set up multiple logging streams for riemann. I have decided to use the simple Clojure file write function to set up additional streams. However, the file is written to as soon as riemann is reloaded but results in a null pointer exception when the relevant event is called and the file needs to be written to.
(where (and (or (tagged "source1") (host "shubham"))
(not (= (:installation_id event) "default")))
(smap (fn [event] (prepare-influx-event event {:time-unit :nanoseconds}))
influx
)
(let [wrtr (io/writer "/var/log/riemann/test.txt" :append true)]
(.write wrtr "Listen please1\n")
(.close wrtr))
;;(spit "/var/log/riemann/test.txt" "Listen please2\n" :append true)
)
the riemann config contains a Clojure expression that is run when riemann starts. The result of running this expsreassion, that is the thing that evaluating it returns, is then used to process all the events. Riemann's config file is a function, which returns a function that will do the actual work. (insert yo'dog memes here)
In this case, when riemann loads that last expression it, while it's getting ready to run, it will open the file, write to it, close it. then it will take the result of closing it and treat that as the function to handle events.
the result of closing a file is null, so it will later try to "run" that null as a function and a NPE results.
you likely want an smap around the let, or just remove the close as you want riemann to keep this file open the whole time it runs. depending on what your going for you may consider making the call to smap above be the last expression inside the let.
below this line is purely my opinion, and not part of the answer:
you almost certainly want to use a proper logging-thing to log stuff to disk on the riemann host. These hosts tend to run for a long time uninterrupted (i tend to leave them a couple years) and if you have it writing to a single file, that file will eventually encounter physics (full disk, size limit etc.) and then if you ssh in and delete it, no space will be freed because riemann will still have the file open. This somehow seems to always happen during some event where you'd really rather monitoring was working. Using a thing with log-rotation is generally a good idea.
I'm very new to using lisp, so I'm sorry if this is a trivial question. I haven't been able to find solutions after a while googling, though I'm sure that this is fault on my part.
So. I'm trying to write a command which will revert all open buffers. Simple. I just do
(setq revert-without-query (buffer-list))
(mapc 'revert-buffer (buffer-list))`
Unfortunately, this ends up failing if there are any buffers which aren't associated with files- which is to say, always.
Doing C-x C-b to list-buffers prints something like
CRM Buffer Size Mode File
init.el 300 Emacs-lisp ~/.spacemacs.d/init.el
%scratch% 30 Test
Ok. Easy enough. If I was allowed to mix lisp and python, I'd do something like
(setq revert-without-query [b for b in buffer-list if b.File != ""])
;; Or would I test for nil? Decisions, decisions...
Upon some digging, I found that there exists remove-if. Unfortunately, being completely new to lisp, I have no idea how to access the list, their attributes, or... well... anything. Mind helping me out?
One possibility would be checking buffer-file-name which will return nil if the buffer isn't visiting a file, eg.
(cl-loop for buf in (buffer-list)
if (buffer-file-name buf)
collect buf)
or
(cl-remove-if-not 'buffer-file-name (buffer-list))
You probably want to revert dired directories also. Any type of buffer can have its own specialized revert (see revert-buffer-function). So you probably want to check for both buffer-file-name and dired-directory being non-nil.
(dolist (b (buffer-list))
(when (buffer-live-p b)
(with-current-buffer b
(when (or buffer-file-name dired-directory)
(revert-buffer 'ignore-auto 'noconfirm)))))
You can also use the ignore-errors hammer, but you're probably better off fixing corner cases as you encounter them.
Is there a way to get a dump of all the source code I have entered into a repl session. I have created a bunch of functions using (defn ...) but did it 'on the fly' without entering them in a text file (IDE) first.
Is there a convenience way to get the source back out of the repl session?
I note that:
(dir user)
will give me a printed list of type:
user.proxy$java.lang.Object
so I can't appear to get that printed list into a Seq for mapping a function like 'source' over. And even if I could then:
(source my-defined-fn)
returns "source not found"...even though I personally entered it in to the repl session.
Any way of doing this? Thanks.
Sorry, but I suspect the answer is no :-/
The best you get is scrolling up in the repl buffer to where you defined it. The source function works by looking in the var's metadata for the file and line number where the functions code is (or was last time it was evaluated), opening the file, and printing the lines. It looks like this:
...
(when-let [filepath (:file (meta v))]
(when-let [strm (.getResourceAsStream (RT/baseLoader) filepath)]
(with-open [rdr (LineNumberReader. (InputStreamReader. strm))]
(dotimes [_ (dec (:line (meta v)))] (.readLine rdr))
...
Not including the full source in the metadata was done on purpose to save memory in the normal case, though it does make it less convenient here.
I want something similar to Emacs C++, opening corresponding header file except that I want to
1) Always automatically open the corresponding header; and
2) Do that in another emacs instance (if someone came up with a solution that made all other emacs instances do this, it would be fine also.)
Note that I use emacs in the terminal mode so I can't do https://superuser.com/questions/102163/how-to-split-emacs-over-a-dual-monitor (or at least I do not know how).
A simple solution to 2) is to run an emacs instance with
server-mode enabled in the second terminal and command it from the
main emacs instance by using server-eval-at.
To launch the slave, run:
$ emacs --eval '(progn (setq server-name "ff-slave") (server-mode 1))'
Then use the following code to command it:
(require 'server)
(require 'find-file)
(defun command-ff-slave ()
(interactive)
(save-excursion
(let ((b (ff-other-file-name)))
(if (null b)
(message "Found no other file")
(server-eval-at "ff-slave"
`(find-file ,b))))))
Calling command-ff-slave from the main emacs instance
should open any related file in a new buffer on the slave server.
Because I use Emacs for many things these days I would like to only load cedet.el when I open a c/C++ source or header and not everytime emacs starts since it takes a significant toll on the startup time.
Right now the beginning of my init file looks like this:
(load-file "~/.emacs.d/plugins/cedet/common/cedet.el")
(semantic-load-enable-excessive-code-helpers)
;;(semantic-load-enable-semantic-debugging-helpers)
(setq senator-minor-mode-name "SN")
(setq semantic-imenu-auto-rebuild-directory-indexes nil)
(global-srecode-minor-mode 1)
(global-semantic-mru-bookmark-mode 1)
And it keeps going.
Is there a way to do this?
my emacs startup improved dramatically after i learned to use eval-after-load and autoload.
if you have a mode you only want loaded when you open a file of the type, add something like this to your .emacs (assuming foo-mode is defined in foo-mode.el on your load path):
(autoload 'foo-mode "foo-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.foo\\'" . foo-mode))
if you have some helper libraries which you only want loaded after you load a "main" library, add something like this to your .emacs (assuming bar-mode is a secondary mode which enhances foo-mode):
(eval-after-load "foo-mode"
'(progn
(require 'bar-mode)
;; ... do other bar-mode setup here ...
))
so, in your case, you probably want to setup cedet using eval-after-load c++-mode.
You could do it like this:
(add-hook 'c-mode-common-hook (lambda ()
(load-file "~/.emacs.d/plugins/cedet/common/cedet.el")
;; any code dependent on having this file loaded
))
If loading the file (or doing the other commands) several times is a problem, you should of course first check whether this file was already loaded (either test for something defined in cedet.el, or maintain an is-loaded flag yourself).
Edit: Such a flag might look like this:
(setq need-to-load-cedet-p t)
(add-hook 'c-mode-common-hook (lambda ()
(if need-to-load-cedet-p
(progn (load-file "~/.emacs.d/plugins/cedet/common/cedet.el")
(setq need-to-load-cedet-p nil))
;; code that should only be executed once after cedet is loaded goes here
)
;; code that should be executed every time a new buffer is opened goes here
))