How to open a code block using emacs org-mode in a specific window - emacs

When working with org-mode I would like to edit a code block in a specific window.
While org-mode does allow some customization with respect to which window a code block will open in, it is quite limited. The four options currently available for the org-src-window-setup variable include current-window, other-window, other-frame, and reorganize-frame. However, these do not accomplish my goal.
I would like to either be able to specify a specific window and/or use windmove-right, for instance, from the windmove package. At the moment, I can only specify one of the four options above. Also, other-window, does not actually go to the other window. Instead it opens a vertical split and creates a new window. At least in my setup.
Is there a way to alter what options the org-src-window-setup variable accepts? Or perhaps there is another solution?

You are looking for:
C-c '
which opens a new window for code editing. You insert the code in your file by saving the buffer
C-x C-s
or by closing the code buffer with
C-c '
For code block there is a shortcut (yasnipet)
<s [tab]
More: orgmode documentation

Related

Emacs - How do I get projectile to open file in current window?

I've spent a whole day on this now. Say I open emacs and press C-c p p to open projectile-switch-project then RET to select a project, emacs opens a new window horizontally (on top of the previous) with the current buffer.
What I need is for projectile to use the already existing window and not open a new one. I've gone through every single line of my config and can figure out what is causing it.
I'd have posted my config but it's split over multiple files which will make it impractical to link to here.
The related packages I can think of which I use are:
projectile,
ivy swiper counsel - trilogy
What I've tried so far is start emacs without loading (ivy swiper counsel) and also I've tried replacing all my projectile code with bare minimum:
(use-package projectile
:ensure t
:init
(projectile-mode +1)
:bind (:map projectile-mode-map
("s-p" . projectile-command-map)
("C-c p" . projectile-command-map)))
which didn't work either.
I'm not expecting any specifics since it's a hand crafted config however I'm hoping for general pointes as to where to look for the possible cause.
I'm researching more to see if i can find a better way for you, but this is what i have so far...
If you want to look around the customization options just type M-x customize. I found a ton of options you can browse through. Projectile was listed under "Convenience" and frames/windows were listed under "Environment". You can also search packages you might be interested in for more customization if you have MELPA installed.
Considering the way that buffers and windows work I don't think you can just replace the content inside the buffer with the content of another file. I think (or at least how I've been using Emacs) you will always open a new buffer to open a file and close old buffers if needed.
From what I was reading, buffers are like interfaces between Emacs and the file you're peering into. It sets up a connection, points to the file, and creates a name for the buffer (usually from the file name unless you change it). Something I find interesting is you can even have multiple buffers open to the same file and as you type on the screen in one buffer the text should show up in the other buffer in real time.
I was reading some documentation on it and I think the command you're looking for is C-x C-f or C-x d, which opens DiredMode. The first one opens your home directory and the second opens the current directory for the file in your selected buffer. This will open a mini-buffer to search through files and when you choose the file it should open the file in a new buffer on top of the buffer you were looking at initially.
Then you can use C-x b to list and move between other buffers that are already open.
Also, M-x projectile-find-file is a command you can use to search files and get the same outcome. I don't have that set to a key-binding so I don't know if there is a default, plus I'm using Spacemacs with evil-mode, so not everything is the same as original Emacs.
Also, maybe look into extension you can get from MELPA like Treemacs

Reftex-toc prevent vsplit on goto

I am currently using spacemacs with auctex. When I use reftex-toc and goto an item then it performs a vsplit and shows the content in the right window. How do I prevent this splitting behaviour? I would like it to open in the current buffer from which the command was issued.
It is related to reftex-toc.el.
I added this hook to maximize the newly opened window:
(add-hook 'reftex-toc-mode-hook 'spacemacs/toggle-maximize-buffer)
but it is a suboptimal solution, as it influences other splits I might have made.
What you describe could be related to the way you select an item.
In normal Emacs (not Spacemacs), I see that SPC is bound to reftex-toc-view-line which behaves just how you describe it. But RET is bound to reftex-toc-goto-line-and-hide which seems to do what you want.
Maybe you just need to find out where that function is on your keymap.

Emacs Comint History: Search Rather Than Navigate One By One

I would like to, after switching to the buffer where I usually run commands, navigate the history by searching it, rather than navigate one-command-at-a-time at the end of the buffer (e.g. C-p).
Basically I would like to "Reverse I-search" the command history at the end of the buffer, rather than search the buffer.
Did anyone code a working solution? Note that I noticed there is a Command History buffer available, but here it is just a bunch of text and it is not grouped well enough I think to use.
As in a terminal, you can use M-r to search backward. It works in comint-mode, but it also work elsewhere, like in M-x (M-xM-rpatternRET).
Yes, with Icicles.
In Icicle mode, command icicle-comint-search is bound to C-c ` in shell buffers. It gives you the behavior you are looking for. It is described here.
It uses only stuff that is in the currently visible history as candidates, however. If you want to access stuff from your history from previous sessions then use command comint-input-ring, bound to C-c TAB, instead. (This is explained in the same doc.)

Elisp: Buffer Menu

Every time I hit CTRL + Left click in Emacs I get a list of all opened buffers.
How can I change the default output in order to pop up a menu customized by myself, I have something like this in mind:
Buffer Menu
-----------
dot.C > ex1.c
dot.java ex2.c
dot.lisp ex3.c
dot.?
...
-----------
For instance, every .c file would be stored inside dot.c entry as showed above.
Are you saying that you'd have one menu for .c files, and another for .h files, even though they're both using the same major mode? The standard menu categorizes based on major mode, so I think you'd need custom menu code to achieve that.
A hacky approach which springs to mind would be to define minimal derived major modes in order to associate each with a different filename extension, and then you could use the existing menus to achieve your goal.
If you didn't mean that, and grouping by major mode is fine, then the current system should already provide a solution.
In either case, the following may prove useful:
How do I set the number of items in the mouse buffer menu in Emacs?
M-x apropos-variable RET mouse-buffer-menu RET

Emacs - Multiple columns one buffer

I'm trying to edit some assembly code which tends to be formatted in long but thin listings. I'd like to be able to use some of the acres of horizontal space I have and see more code on-screen at one time. Is there a method for getting Emacs (or indeed another editor) to show me multiple columns all pointing to the same buffer?
C-x 3 (emacs) and :vsplit (vim) are great for multiple separate views into the code, but I'd like it to flow from one column to the other (like text in a newspaper).
See follow-mode.
Excerpt:
Follow mode is a minor mode that makes two windows, both showing the same buffer, scroll as a single tall “virtual window.” To use Follow mode, go to a frame with just one window, split it into two side-by-side windows using C-x 3, and then type M-x follow-mode. From then on, you can edit the buffer in either of the two windows, or scroll either one; the other window follows it.
In Follow mode, if you move point outside the portion visible in one window and into the portion visible in the other window, that selects the other window—again, treating the two as if they were parts of one large window.
I use this function to invoke follow-mode, although it would need customization for a different screen size:
;;; I want a key to open the current buffer all over the screen.
(defun all-over-the-screen ()
(interactive)
(delete-other-windows)
(split-window-horizontally)
(split-window-horizontally)
(balance-windows)
(follow-mode t))
The "Multipager" plugin for Vim can do this with VIM splits for people who want to get this behavior in Vim.
Get it from Dr. Chip's page: http://mysite.verizon.net/astronaut/vim/index.html#MPAGE
Docs: http://mysite.verizon.net/astronaut/vim/doc/mpage.txt.html
Vim can do this using :vsplit - and you can have the same buffer open in multiple "windows" (which are actually sections within a single "window").
Documentation here
A quick look at the emacs wiki doesn't show a mode like you describe. However, it shouldn't be too hard to write one... You just need to split the window with C-x 3 and move the text in the other window down, and whenever you move the text, do the same to the other window...
Problems may occur when you get to the bottom of the buffer, do you want the cursor to immediately go to the other window at the top?
Hmm, maybe its not that easy. But it should still be doable...
this is the default behaviour of emacs when splitting the window (C-x 3 for vertical split)
you get two columns which both have the current buffer open
Use vertical-split with C-x 3. This will split the current buffer into two columns that you can switch between with C-x o.