Creating, recreating many Emacs-windows - emacs

From time to time I would like to create a bunch of say 8 windows with some fixed names, with some shells, all split vertically. So I do a lot of C-x 2 and rearrange the window size. Isn't there a better way to do this?
So the desktop saver is no help to me, unless I missed something.
(By windows, I mean emacs-windows, not the windows "window-managers" are built-for which you can Alt-Tab to)

You can store your current window layout to the Configurations register
However, to make it persistent across sessions, you might need a tool like Policy Switch.
Emacs Screen also looks very promising for what you want.
This is something that I have been meaning to do for myself for a long time; appreciate the nudge ;)

While there are various prepackaged solutions for recording and saving windows and frame congurations as alluded to in the other answer, it is quite easy to do this directly.
You can call 'make-frame' directly with the frame parameters you want. An example may look like this:
(make-frame '((name . "(SHELL)")
(icon-name . "(SHELL)")
(icon-type)
(top . 720)
(left . 1300)
(height . 30)
(width . 81)))
This call will not only create the frame (in case you are running under a windowing system) but also return the newly created frame.
If you want a quick peek at what parameters are available, you can make a call like this:
(frame-parameters)
which will return the parameters of the currently selected frame.
You can change one or more parameters of a frame with 'modify-frame-parameters' and get a list of all frames with 'frames-on-display-list'.
There are many more nifty functions that allows you to deal with frames. Check the documentation for more info.

Related

Is there a region change hook in emacs lisp?

I'm trying to get the content of current selected region in buffer. I'm aware of idle timer, but a hook should be more efficient/cleaner...
Not sure what you mean by "region change". If you mean "the text in the region is modified", then you'll need to use after-change-functions. If you mean that the selected text is modified by changing its bounds, then you'll probably want post-command-hook or maybe an idle timer (which is not less efficient than a hook, the main difference is that you get less guarantees about when it gets run; e.g. it won't be run between two commands if there's no idle time between the two, as is the case when running a keyboard macro).
A way to go seems to advice handle-shift-selection. AFAICT this function is called with every region-change by keyboard. Resp. advice mouse-drag-region.

Can I disable window-splitting in a particular frame?

I'm a developer who uses emacs. In emacs I use multiple frames (what most people would call X windows), and the compile function for my builds. I like to have one frame for my compilation buffer, and the others for source. That allows me to navigate to build errors easily and get a nice big view of the source I'm investigating along side a nice big view of my build output. This works fine when I use the 'next-error' function from a source frame.
But when I move my pointer into the compilation frame, and click on an error, it vertically splits that frame to show the relevant source. I want it to show the relevant source in one of my other frames.
Is there a way to "lock" a frame so that it won't be split into windows, and so other frames will be used instead? I'm OK if it splits one of my other frames to display the new source files - just not the compilation frame (because that means I have to unsplit that frame and then switch the buffer of a different frame to display the buffer in question - that's cumbersome).
Alternatively it would be fine if I could use a different mouse button on an error in the compilation buffer to say "visit this file and line in a different frame".
I believe you can achieve your goals by making the window in your "compile frame" dedicated:
Functions for displaying a buffer can be told to not use specific windows by marking these windows as dedicated to their buffers.
Interactively, M-x set-window-dedicated-p should make your window dedicated.
From elisp, something like
(set-window-dedicated-p (selected-window) 1)
should do the same. Replacing 1 with t will make the window strongly dedicated:
As a special case, if flag is t, window becomes strongly dedicated to its buffer. set-window-buffer signals an error when the window it acts upon is strongly dedicated to its buffer and does not already display the buffer it is asked to display. Other functions do not treat t differently from any non-nil value.

Emacs - how to use colors to visually accentuate the function the cursor is in?

Inspired by ia Writer's focus mode, I'm interested in using font + background colors in emacs to accentuate the function the cursor is in and visually cue the rest of the code as the background (I use C++, but it would be nice if this worked regardless of the programming language).
Ideally the font color of code outside the function would be dimmed (this is how focus mode works). A simpler solution probably be to change the background color slightly for the function that the cursor is currently in. How can this be done?
Nothing like this exists AFAIK. If you want it to write it yourself, here is a sketch:
Write a routine that determines the boundaries of the current function. The easiest way to do this is with (bounds-of-thing-at-point 'defun).
Write a routine that, when given the bounds of a region, gets the background face property of the region of the region, darkens it, and applies the new face to the region.
Override font-lock-fontify-region-function (see here) with a routine that calls the original value of this variable, differences the region given with the region of the current defun (using #1), and then applies routine #2 to the remaining region.
I would prefer overriding font lock to, say, using jit-lock-register because you need to control the order of fontification.
HTH!
Which-function mode is used to highlight the current function. Try it to see if it helps you, and see if this post helps you:
Emacs Setting which-function-mode

Can we make an Emacs buffer to be static/pinned?

I use an Org file to keep track of my activities, because it's often that I am loosing track of what actually I am aiming to do :)
Now, I would like to reserved a top buffer window with only 5 lines tall and show the narrowed todo from that org file. All other window/buffer activites will not touch that static/pinned buffer.
Is there a way to achieve that result???
Thanks!
EDITED : Can we make that certain buffer to have different background Color? I pressume it's not, because all we have is set-background-color... I hope I am wrong..
Maybe setting the variable special-display-buffer-names will set you in the right direction.
(setq special-display-buffer-names
'(("magic buffer" (width . 70)
(height . 7)
(background-color . "green"))
))
to test certainly made a buffer called "magic buffer" turn up in a small and very very green frame. (For real-life use, of course do go through the customize mechanism by all means.)
ETA: And then, there's also this question which might apply here.
If you clock in to the Org TODO item, that task will be displayed in the modeline of the current buffer; you might also find that helpful as a reminder of what you're working on.
The original part of the question is a duplicate. See How do I make this Emacs frame keep its buffer and not get resized? (which is slightly enhanced over the earlier Pin Emacs buffers to windows (for cscope)), and the set-window-dedicated-p function.
YOu can use org-todo-list to show TODO items and org-agenda will show you useful choices such as "M" that filters your TODO items by keyword.
I struggled with the same problem for a while. The best solution I came up with was creating a small Emacs frame (size: 80x13) for my Org-mode agenda and placing it in an always-visible portion of my screen. (Use "C-x 5 2" to create a new frame.)

Matrix-like Idle Animation for Emacs

As is, my emacs is set up to show green text on a black background. On seeing it, a friend remarked that I just took it because of the Matrix-like appearance it gives. So, now what I want to do is implement an idle animation for it where, like in the matrix, changing text falls down the screen. Like in the zone out functions, it should run after emacs has been idle for a while. How would this be done?
You might want to check out the package zone: M-x zone
The 'zone-pgm-drip is like the Matrix drip, only one character at a time. I'm sure it could be enhanced to be more flood like. Also, the 'zone-pgm-jitter has text flooding down, but it's just the text currently on the screen (so it's horizontal extent is limited to what was already showing). You can just run M-x zone over and over until you find what you like.
If you want to limit the choices zone uses, you can restrict the array that zone uses:
(setq zone-programs [zone-pgm-jitter])
The choices for zone-programs are:
zone-pgm-jitter
zone-pgm-putz-with-case
zone-pgm-dissolve
zone-pgm-explode
zone-pgm-whack-chars
zone-pgm-rotate
zone-pgm-rotate-LR-lockstep
zone-pgm-rotate-RL-lockstep
zone-pgm-rotate-LR-variable
zone-pgm-rotate-RL-variable
zone-pgm-drip
zone-pgm-drip-fretfully
zone-pgm-five-oclock-swan-dive
zone-pgm-martini-swan-dive
zone-pgm-rat-race
zone-pgm-paragraph-spaz
zone-pgm-stress
zone-pgm-stress-destress
zone-pgm-random-life
You could install zone-matrix from Marmalade. "M-x package-install zone-matrix"
Looks like someone just made one. It worked for me after a small amount of tweaking:
https://github.com/emacsmirror/zone-matrix
You could just use the xmatrix screensaver, which could probably be modified to run in a window other than the X root if you really want it to run it within emacs. Bonus points if you can modify it to use glyphs based on the text in the current window. By strange coincidence, Jamie Zawinski both wrote xmatrix and large chunks of Lucid Emacs, which was subsequently released under an open-source licence as Xemacs.