I have used emacs for erlang programming. According to http://emacswiki.org/emacs/CompileCommand, I have configure c-c c for recompile.
In the emacs frame, 6 windows are open, top 3 are for erlang source code reading and writing.
In the below windows, one is supposed for the compie window.
But when different windows is active and recompile, the compile window will switch randomly. How to fix it in one perticular window?
If you start reading at C-hf display-buffer RET (or in the manual at M-: (info "(elisp) Choosing Window") RET), you'll find a bunch of ways in which you can modify the behaviour.
It can get a little complex, but something like this might be all you need in your recompile function:
(let ((display-buffer-overriding-action
'(display-buffer-reuse-window)))
(compile))
I always use dedicated windows when I want to keep things in the one place, so you might also find that useful to look into:
M-: (info "(elisp) Dedicated Windows") RET
I use the toggle-window-dedicated function from Pin Emacs buffers to windows (for cscope) (see also How do I make this Emacs frame keep its buffer and not get resized?)
Related
I'm a beginner in Clojure and for some reasons I decided that Emacs would be a good choice, because of its usage among the clojurists.
But something that's really anoying me is that Emacs (for working with Clojure projects) opens a bunch of buffers. i.e, when I click "Read a directory to operate in its files" and select the lein's project root, I need to select myproject.core.clj and Emacs keep all the super dirs openned in other buffers. When compiling with cider and working with many clj files, it's painful to keep on alternating through all those buffers.
How can I limitate the numbers of buffers that Emacs leave openned?
(I know C-x k)
(Sorry for any English mistakes)
I had a lot of trouble with this same problem when I first started using Emacs. The solution is to use something other than C-x b or C-x C-b to switch between buffers. In particular:
I use Projectile's C-c p f to switch to arbitrary files in my project. It works very nicely because it takes your .gitignore into account. This can be annoying in some cases, but for the most part it works very well.
I use project-explorer to browse through a tree view of all the files in my project. The ignore features of project-explorer aren't quite as nice as those of Projectile, but you can toggle them using M-o when you need to, which is a feature Projectile doesn't have. project-explorer-open doesn't have a default binding, so I bind it to C-x p.
I use Ido and ido-ubiquitous to make all selection commands (including C-c p f) much easier to use.
If you lose your REPL buffer in CIDER, you can get it back instantly using C-c C-z.
If you already have multiple windows in front of you, windmove provides an extremely fast way to switch between them.
You'll generally end up with a lot of open buffers anyway, but since you now have an easy way to switch between them, that's no longer a problem. You can find a full example of this sort of setup in my personal Emacs config.
Personally, I use C-x C-f to open files, and don't bother with opening buffers for directories.
Are there any modes or resources for Kawa in Emacs? I've checked, but am not able to find any. Mostly, I'd like to be able to run a Kawa REPL inside of Emacs, but some kind of completion/syntax checking would be great too.
I don't have any prior experience with Kawa, but I have a "universal" way to deal with REPLs: plugin isend + some hacks
Follow the instructions in section 2 and section 3 of this article http://wenshanren.org/?p=351#sec-2 to setup isend (it's a bit tedious, please let me know if you have any problems)
Open a shell in Emacs, assume the buffer name is *shell*
M-x shell
Open Kawa REPl in *shell*
CLASSPATH=/usr/local/lib/kawa.jar && export CLASSPATH && java kawa.repl
Create a new buffer test.kawa and turn on lisp-mode M-x lisp-mode (you can use any mode you want)
Associate *shell* with test.kawa M-x isend-associate *shell*
Now type some sexps in test.kawa, select them and press C-Enter to send them *shell* for execution (the cursor won't move)
In Emacs I'm editing some source code, and I hit <tab>. Emacs indents the line to n spaces. I'd like to change the amount that indents for that kind of line. How do I figure out what rule emacs applied to indent that line by n spaces?
I want to change n, but I need to figure out which of the many indentation-related variables Emacs just used.
A generic answer is difficult. Some modes will make this more apparent than others, but in the general case (as they are free to implement indentation however they wish) I don't think you'll get away from needing to read some elisp.
Starting with the binding for TAB will work, but might be slightly time-consuming depending on how many layers of indirection are involved.
If you know that the major mode in question implements its own indentation, then one (non-rigorous, but fast) approach that you could try to help track down the functions being called is to use ELP, the built in elisp profiler. elp-instrument-package will instrument for profiling all functions with names matching the prefix string argument you specify. Therefore you might do something like the following in a PHP file (noting that php-mode tells you that it is derived from c-mode)
M-x elp-instrument-package RET php- RET
M-x elp-instrument-package RET c- RET
M-x elp-instrument-package RET indent RET
Now type TAB in your source code, and run M-x elp-results to see which of those instrumented functions were called.
At this point you're on your own -- look for the likely suspects, and see what the code is doing -- but it can be a handy way to filter the search.
Once you've finished, use M-x elp-restore-all to prevent any further profiling.
If you're using a mode based on cc-mode (e.g. c-mode, c++-mode, java-mode, etc.), you can hit C-c C-s and it'll tell you what syntactic category the line is. If you want to change it, hit C-c C-o and you'll be guided through the process. Check out the cc-mode docs on customization for more details: https://www.gnu.org/s/emacs/manual/html_node/ccmode/Customizing-Indentation.html
If you happen to enjoy getting your hands really dirty, there's always the elisp debugger to tell you just what Emacs is up to.
If you hit C-h k TAB you'll find the function that Emacs is running (e.g. indent-for-tab-command) then you can do M-x debug-on-entry RET indent-for-tab-command RET. Now whenever you hit TAB you'll pop up a debugger and can watch the execution step by step.
Depending on your taste for debugging, it's either a maddening or enlightening experience. Either way, don't forget to M-x cancel-debug-on-entry when you're done.
I've recently started using emacs and I'm enjoying using it for the most part. The only thing I'm not enjoying, is switching between buffers. I often have a few buffers open and I've grown tired of using C-x b and C-x C-b, are there any packages that make switching between buffers easier? I've looked into emacs wiki on switching buffers and I'd appreciate insight/feedback on what are are using/enjoying. Thanks.
UPDATE: iswitchb-mode is obsolete in Emacs >= 24.4, replaced by ido.
All of the features of iswitchdb are now provided by ido. Ross provided a link to the documentation in his answer. You can activate with the following in your .emacs (or use the customization interface as Ross suggests):
(require 'ido)
(ido-mode 'buffers) ;; only use this line to turn off ido for file names!
(setq ido-ignore-buffers '("^ " "*Completions*" "*Shell Command Output*"
"*Messages*" "Async Shell Command"))
By default, ido provides completions for buffer names and file names. If you only want to replace the features of iswitchb, the second line turns off this feature for file names. ido will ignore any buffers that match the regexps listed in ido-ignore-buffers.
The behaviour described below for iswitchb-mode applies equally to ido for switching buffers.
iswitchb-mode (Emacs < 24.4)
iswitchb-mode replaces the default C-x b behaviour with a very intuitive buffer-switching-with-completion system. There are more sophisticated options, but I've never needed more than this.
After you hit C-x b, you are presented with a list of all buffers. Start typing the name of the buffer you want (or part of its name), and the list is narrowed until only one buffer matches. You don't need to complete the name, though, as soon as the buffer you want is highlighted hitting enter will move you to it. You can also use C-s and C-r to move through the list in order.
You can turn it on by default with this in your .emacs:
(iswitchb-mode 1)
You can also tell it to ignore certain buffers that you never (or very rarely) need to switch to:
(setq iswitchb-buffer-ignore '("^ " "*Completions*" "*Shell Command Output*"
"*Messages*" "Async Shell Command"))
You can use C-x <right> (next-buffer) and C-x <left> (previous-buffer) to cycle around in the buffer ring. You could bind S-<right> and S-<left> to these functions. (S is the "super-key" or windows-key). This way you can save some keystrokes.
Moreover, note that C-x b has a default entry, i.e. it displays a standard value (most of the time this is the previously viewed buffer), so that you don't always need to enter the buffer name explicitly.
Another nice trick is to open separate windows using C-x 2 and C-x 3. This displays several buffers simultaneously. Then you can bind C-<tab> to other-window and get something similar to tabbed browsing.
M-x customize-group ido then set Ido Mode to Turn on both buffer and file and set Ido Everywhere to on. Then click the Save for future sessions button at the top and enjoy ido magic for both files and buffers. Read the docs to get a sense of how to use ido.
Also, take a look at smex.
ido-mode provides an efficient way to switch buffers.
ibuffer is best for managing all opened buffers.
anything is good for selecting an interested thing from different
sources. (for eg: a single key can be used to switch to another
buffer or to open recently closed file or to open a file residing
in the same directory or ... anything you want ... )
If you've looked at the Emacs Wiki, you probably have all this information already, but here are a few other relevant Q&As:
Emacs: help me understand file/buffer management
Buffer switching in Emacs
How to invoke the buffer list in Emacs
My toolkit consists of ibuffer, windmove+framemove, winner-mode, and a custom binding to make C-xleft/right and C-cleft/right less of a hassle to use.
I have mapped the "ยง"-key to 'buffer-list and I find it to be very efficient.
I've started using anything for a couple of days and I'm really liking it: http://www.emacswiki.org/emacs/Anything .
Emacs-fu has an good intro to anything: http://emacs-fu.blogspot.com/2011/09/finding-just-about-anything.html
My favourite function for this is helm-mini which is part of helm.
As other helm functions, it allows incremental narrowing of the selection. It also searches your recently visited buffers, which is a really nice way to re-open a buffer. Helm can be a little surprising at first and as a new Emacs user, I found it visually overwhelming and I preferred ido or ibuffer which have been suggested in other replies. But now I absolutely love it and use it all the time for countless things.
Something that I realized by accident and that can be useful:
mouse-buffer-menu is by default bound to <C-mouse-1> (Control key + mouse left click) and opens a popup with a list of the current buffers.
I'm using pdb to debug Python programs and am unhappy with it's behaviour.
I have the screen divided into multiple emacs windows, and when I execute pdb, it (randomly?) replaces one of the windows with the output of the *gud* debugger.
Also, when a breakpoint is encountered, even if the debugging buffer is already visible in a window, it usually puts this buffer into another window, and replaces another of my windows with the contents of the source file. (incidentally I like that it jumps to the correct line in the source file)
How can I disable gud/pdb from managing my windows for me? Is it possible in emacs to prevent all programattic manipulation of windows & screen layout?
Edit: I found the answer that partially solves this in another post: toggle dedicated windows
I tried all these approaches without success on Emacs 24.
If you are still interested I reverted to the old gdb behavior using 'gud-gdb' which implements the old behavior of gdb/emacs interaction (no dedicated-windows and no I/O buffer). If you don't want to call M-x gud-gdb when you use it, you can define an alias for M-x gdb
Look into sticky windows.
I have a solution that prevents the gdb from stealing windows. It works with Emacs 24.4 (2014-07-18 snapshot) and does not require dedicating buffers. The benefit over other answers is you won't have to bother dedicating and undedicating buffers whenever you change buffers, which quickly becomes tedious.
Place this advice in your .emacs:
(defadvice gdb-inferior-filter
(around gdb-inferior-filter-without-stealing)
(with-current-buffer (gdb-get-buffer-create 'gdb-inferior-io)
(comint-output-filter proc string)))
(ad-activate 'gdb-inferior-filter)
This effectively replaces this function as defined in gdb-mi.el and removes the branch that calls gdb-display-buffer, which is the cause of the window thievery.
You should use Sticky Windows to make your windows and buffers stick where they are but Sticky Windows won't stop gud/pdb from trying to steal your windows. When gud/pdb can't steal your source code window, it opens a new Emacs Frame even if there is another window on the current frame.
This comes from the fact that the function that tries to jump to the gud-pdb buffer (py-pdbtrack-track-stack-file) calls function pop-to-buffer with argument OTHER-WINDOW set to t.
To circumvent this behavior for all libraries that calls pop-to-buffer, you could cancel the role of OTHER-WINDOW by defining an advice on pop-to-buffer (in your .emacs) :
(defadvice pop-to-buffer (before cancel-other-window first)
(ad-set-arg 1 nil))
(ad-activate 'pop-to-buffer)
You should also customize variable pop-up-windows to nil in order to force display-buffer (the low-level routine used to display a particular buffer on windows and frames) to not create a new window.