I've wrestled quite a bit with emacs tabbing, but haven't been able to figure this one out.
In ruby-mode:
SomeClass.create(
this_is: where_i_want_to_tab,
because: that_is_how_we_do_it
)
SomeClass.create(
this_is: where_emacs_wants_to_put_it,
but: my_pull_request_aint_gonna_be_merged_like_this
)
This is maybe a code style decision that the ruby-mode designers made, but is it possible to configure it?
This behavior of ruby-mode cannot be configured, but it was changed in Emacs 24.4 (which will be released soon). There code like this:
SomeClass.create(
this_is: where_emacs_wants_to_put_it,
but: my_pull_request_aint_gonna_be_merged_like_this
)
will be indented like this:
SomeClass.create(
this_is: where_i_want_to_tab,
because: that_is_how_we_do_it
)
which is consistent with the existing good practices.
Turns out you can configure this in 24.3:
(setq ruby-deep-indent-paren nil)
Related
I'm using OSX 10.9, iTerm2, Emacs Prelude, and Clojure with all the modes that entails most relevantly, smartparens. Good so far.
The short version is: has anybody out there found a harmonious way to use all of this together with OSX Mission Control?
The longer version goes: I want to be able to use commands like sp-forward-slurp-sexp, which has a default keybinding of C-<right>, better known as the default OS-level shortcut for "switch Spaces right via Mission Control." I can re-map that fairly easily (say, to C-Shift-<right>) -- but now, I discover that C-<right> actually seems to be sending something like M-[1;4A. Instead of triggering sp-forward-slurp-sexp, you get sp-wrap-with-pair "[". Uhm.
I dug up this dissertation on re-mapping keys, which is very thorough, but also involves re-mapping rather a deal of stuff, then disabling the parts of paredit that are listening for the M-[ command. While this technically seems to work, I actually rather like having sp-wrap-with-pair enabled. Perhaps a better option would be to embrace the theoretically equivalent C-( -- except iTerm2 only interprets that as a literal 9, and C-) as 0. This SO post chews on this problem, and gets as far as a tantalizing comment suggesting that C-( and C-) simply be re-mapped to escape sequences that emacs can map back to C-( and C-) -- but frankly, I haven't a clue how to figure out what escape sequences those should be.
Bringing it all home: has anybody found a way to use all of these tools (Mission Control, iTerm2, Emacs Prelude, smartparens) together without having to re-wire or disable parts of some or most of them? Or: who has the most elegant re-wiring? Anybody figured out the C-)-to-escape-sequence-back-to-C-) trick yet?
Edit
Stabbing in the dark, I've done the following:
1. Set iTerm to send an escape sequence for the keyboard shortcut Ctrl-Shift-0 (C-S-)) of SPRTPRN.
2. Put this in my emacs config:
(define-key input-decode-map "\eSPRTPRN" [C-right-paren])
(global-set-key [C-right-paren] (kbd "C-)"))
...it does not work, but I've a hunch I'm getting closer. I think.
Edit, Again
I realized something: the notion that Shift doesn't work here doesn't make sense to me. At least on my emacs install, M-< and M-> jump to the beginning and end of a buffer, respectively -- and to use those commands, I have to actually press Meta-Shift-<. Huh.
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.
One of my colleagues uses TextPad, and one feature I found really useful is the Auto-Reload. (The feature has been described in this SO quesion: Alternative to TextPad's Prompt to Reload File). Basically, it keeps reloading the file without any prompt from the user, which is really helpful when monitoring log files that are updated in real-time. Is there something similar available for Emacs? If not, can anyone whip up the required elisp magic?
M-x auto-revert-mode
I should add that for log tails, there is the more specific auto-revert-tail-mode, and that if you like it as a general feature (my case), you can turn on global-auto-revert-mode, to revert all buffers. Beware of remote files in that case.
If you want auto-revert to apply everywhere you can also use global-auto-revert-mode. Add
(global-auto-revert-mode 1)
to your .emacs
Here's my preference, FWIW: I do not use auto-revert. Instead, I bind f5 to this command:
(defun revert-buffer-no-confirm ()
"Revert buffer without confirmation."
(interactive) (revert-buffer t t))
Sounds silly, but that simple change makes all of the difference. This is what f5 does anyway on MS Windows, so it's a habit that works in all applications (on Windows).
Note that I do not change (e.g. remap) any bindings for revert-buffer. I use this only when I explicitly want to revert without confirming (which is quite often, in practice).
HTH.
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.)
When I do indent-region in cperl-mode
if ($x) { next; }
Emacs reformats it to:
if ($x) {
next;
}
How can I make it stop doing that?
Note: the question originally said that this reformatting happens when yanking. I have yank setup to indent-region as well.
(setq cperl-break-one-line-blocks-when-indent nil)
Assuming you don't want it to autoformat when you type that kind of code either, simply change the bindings of {} to self-insert-command instead of perl-electric-terminator.
I can't find anything in cperl-mode that would do this. Try starting emacs with no customizations:
$ emacs -q
and then turn on cperl-mode in the scratch buffer:
M-x cperl-mode
Paste your text; it should look like the original (i.e. all on one line). Then start customizing cperl-mode:
M-x customize-group<RET>cperl<RET>
setting each variable individually for the current session only, and trying the paste in between each setting. If you suddenly find the behavior you're seeing, you have a starting place to look further (it could be a combination of options).
If you get cperl fully customized and it still doesn't behave "incorrectly" then you need to start looking at what other packages could be causing it. It could take a while....
It doesn't work that way for me, I just tried it with various settings in the Toggle... submenu under the Perl menu. Could there be something other than Cperl mode that's making that happen?
Without sounding like I'm giving a copout answer, why not just do this?
next if $x;
Same code, same effect, and just as readable (to me, at least), but I bet emacs won't try to reformat it.