trying to add custom widget to spacemacs spaceline - emacs

I'm struggling to find the best practice for adding in a new widget in spaceline within spacemacs.
The best I have so far is to redfine the battery segment:
(spaceline-define-segment battery
(shell-command-to-string "echo 'hello'"))
but this then slows down spacemacs considerably so it seems like there must be a refresh parameter somewhere? There doesn't appear to be an async-shell-command-to-string function either.
Total emacs newbie here, as you can tell.

Related

Creating, recreating many Emacs-windows

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.

Add content to Emacs minibuffer as the user types in it?

I'm probably going down the wrong path here, so let me know if I am. I'm trying to build a similar user interface to that which Vim's ctrlp and other plugins use, whereby the user is given a prompt, and as they type, results are shown above the minibuffer prompt line.
I've gotten the minibuffer command handling part working fine with minibuffer-with-setup-hook and a local post-command-hook (easy) and can get the results I want to display (verified by just (message)ing them for now).
If I want to show, say, 10 lines of results above that minibuffer prompt line, should I be somehow prepending text to the minibuffer, or using a separate buffer that I'll close once the command finishes? Any pointers to parts of the manual I should be reading to be on the right track with this?
The "minibuffer" is a normal buffer, so you can modify it by inserting/deleting text into it in the normal way. This said, adding text "before" means basically modifying the prompt which might lead to problems down the line. You'll probably be much better off doing something like
(let ((ol (make-overlay (point-min) (point-min))))
(overlay-put ol 'before-string (format "%s\n" myresults)))
I started to write this as a comment, but it got a bit too long ...
TBH, I feel there is room for a lighter weight version of helm. But the reality is helm is good enough, and someone else has already written it.
Neither I nor anyone else (so far) is motivated enough to rewrite it. What you describe as "God" aspect of it is indeed unappealing. But it is possible to load it (huge as it is, with modern computers, it really isn't an issue), and change settings so it is minimalistic.
ido is a simpler alternative, but the style of UI is not exactly how you described.

emacs evil-mode key map

yep I am the one who started to use EMACS but not willing to abandon the VIM skills I learned.
evil is definitely a good thing.
the issue I am encountering is that there too few documentation for this. Obviously I am using a tiny fraction of the key-mappings defined in evil.
So I take a look at the evil-maps.el, and get quite a few question regarding this file:
a lot of the key are not mapped to the function defined there
what is the evil-window-map ? (just find out my self, it is key-bindings for jumping between windows, and to activate it: need to (setq evil-want-C-w-in-emacs-state 1 ) )
what is the operator pending state ?
did evil load all the maps it listed in the evil-maps file into Emacs ?
any better documentation for evil ?
it takes sometime to understand the STATE of EVIL plugin and then those shortkeys just become handy. so the solution is to read the documentation again and again.

Is there a way for Emacs to autocorrect R commands

I'm a relatively new user to R and Emacs and was wondering if Emacs could automatically correct any R commands that i've typed wrong. I know about the alt-/, but I was more thinking along the lines of if i type read.tale, it corrects it to read.table.
Also, I was using emacs the other day and whenever i typed read.table, it showed the usage options (that bit from the help file) in the bottom bit of the window-the minibuffer?. anyway, its not there now, and i don't know what i did to make it go away.
Thanks for your help
Independently of emacs, you can examine your code with the checkUsage function in the codetools package. For example:
> foo <- function(data){
+ read.tale(data,file='temp.txt')
+ }
> checkUsage(foo)
<anonymous>: no visible global function definition for ´read.tale´
Also, you can emacs autocompletion functions (e.g. hippie-expand or dabbrev-expand) to fill in the rest of recently used function and variable names.
If you aint married to emacs, you should give Komodo edit with sciviews-R / sciviews-K a try.
So far it´s the best auto-completion coding I found for R. At least to me the configuration was much easier than emacs, particularly because of binding problems with my exotic (swiss) keyboard. sciviews-R / Komodo
EDIT: I realize this thread is still being read. So in meantinem I got to give it up for RStudio. It has really become THE editor for everyday use for most people. Nice autocompletion, available on all major OS and a really nice context help. Plus some easy export of pdf graphics and much much more. On top R Studio is easy to install – no need to worry how to fire up R from the editor.

Code folding in Emacs [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to achieve code folding effects in emacs
An excellent feature of Dreamweaver is code folding of any lines of text -- recursively!
It's fantastic, I can fold any text or code, regardless of language. I work with existing systems; I don't edit well-written code or code in one language etc. mostly HTML mixed with god-knows-what. Folding lines makes understanding a lot easier and quicker. Sadly, this is the only feature I like in Dreamweaver.
Is there any code folding for Emacs in a similar aim?
There's folding mode, a minor mode. Unfortunately it's intrusive: you have to manually annotate the folds with specialized comments, which clutter the code when you aren't using the mode (or when sharing code with others who don't use it). A better mode would not change your code to work.
Let me add: there's a duplicate of this that's worth a look: How to achieve code folding effects in Emacs.
hide-show (hs-minor-mode) is a minor mode that will do something like this...
The default key-binding to trigger the folding is C-c # C-c which I find pretty cumbersome. But then I don't use it much, either.
You might want to look up the function set-selective-display and the variable selective-display. Not exactly what you want but it lets you hide lines based on indentation level.
I use fold-dwim.el. From the emacs wiki:
fold-dwim.el is a unified user interface for Emacs folding/outlining modes. It supports folding.el, hideshow.el, outline.el, TeX-fold.el, and nxml-outln.el
You can get it here:
http://www.emacswiki.org/emacs/FoldDwim
I have this in my .emacs:
(require 'fold-dwim)
(global-set-key [(C kp-4)] 'fold-dwim-hide-all)
(global-set-key [(C kp-5)] 'fold-dwim-toggle)
(global-set-key [(C kp-6)] 'fold-dwim-show-all)
Keep in mind that you still need to activate hs-minor-mode, folding-mode, etc. but I find it easier to use them this way.
Something else you might look into is nxhtml-mode; it doesn't fold code, but it does highlight mixed code (i.e. HTML and PHP) differently depending on its type. That gives you a similar gain in comprehensibility without the awkwardness of folding-mode. I think that approach is more suited to Emacs anyway, first because code-folding seems like a mouse-oriented idea that doesn't adapt well to the basically keyboard-centric Emacs interface, and second because Emacs eases navigating a large file to an extent that code can stay visible without getting in your way.
If you actually need "something to hide a given region rather than it trying to understand the syntax" (unlike hideshow and other solutions based on parsing) and you "don't want to have to edit [your] code" (unlike folding), then, I assume, you mean you don't want the regions to be persistent between different editing sessions. Then you might use http://www.emacswiki.org/emacs/HideRegion to hide user-selected regions...
(But that's strange. The folding minor mode with persistent marks seems to be a far more convenient solution.)