How do I stop auto-formatting in emacs cperl mode? - perl

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.

Related

Emacs lisp, How to make a newline in IELM?

Even the basic things seem to be hidden behind weird shortcut-combinations.
How can I (hopefully without too many c-m-x-c combinations) create a simple new line?
return evaluates the current line
With C-j. That said, if you have paredit enabled, it should do all the newlines you need automatically.
In my case it was M-j.
I'm currently trying out SpaceMacs, not sure if that has anything to do with it.
Even the basic things seem to be hidden behind weird shortcut-combinations.
If you don't want RET to have contextual behaviour, you can M-x customize-option RET ielm-dynamic-return.
How can I ... create a simple new line?
Only a newline? C-qC-j is the normal way to enter a newline in places where RET does something else. (More generally you can use C-q to insert any character that isn't self-inserting for the current buffer.)
If you want newline + indentation (which is what RET does when contextually appropriate), then M-j will do that (noting that if you are in a comment at the time then the new line will also default to a comment).

emacs makefile-mode for Makefile.include

I use file named Makefile.include as a GNU makefile. I am trying to get emacs use the makefile-mode to use for this file. Alt-X makefile-mode works. Is there a way to tell emacs to use this major mode for this file right after opening automatically?
I tried putting
# _*_ mode: makefile; _*_
in the file but that does not appear to have the right effect. Btw I could not find the list of allowed strings one can use after mode:, so I tried BDSmakefile and some other variations as well.
Thanks.
See this question: Setting auto-mode-alist in emacs, and use the pair ("Makefile\\.include\\'" . makefile-mode).

New to Emacs. When I type ", \" is automatically inserted

As the title states, I'm relatively new to Emacs. I tried out several starter kits but went with Prelude and changed a lot of things around.
Anyway, I've been getting a good handle on everything...until this morning I was working and I typed double-quotes. Normally Emacs would insert a second double quotes right after ("") due to the auto-completion, but I must have accidentally changed something with a keystroke and now when I type ", I get \"\".
Thoughts?
Thank you.
This seems to be an issue with smartparens which prelude installs by default (see the file prelude-programming.el. This behavior is described in detail on smartparens wiki. To ensure that smartparens is causing problems you can can do C-h k" this would print about the command acutally run when " is pressed, if the command is sp--self-insert-command then the following should work
Paste this (setq sp-autoescape-string-quote nil) to your *scratch* buffer, go to the closing parenthesis and do C-xC-e, this will disable the behavior for current emacs session.
To disable the behavior for all future emacs session, assuming that you are using prelude, you will need to add the following to your personal config (basically some file inside /path/to/prelude/personal/).
(setq sp-autoescape-string-quote nil)
This will disable the auto-escaping of the string quotes, completely. If you like this behavior and do not want to disable it completely you can do what #steckerhalter suggests C-q" will insert just one parenthesis.
If the above does not solve the issue then try providing following info in your question which may help us debug the issue,
1) The list minor modes active (this can be obtained by doing C-hm).
2) Output of C-hk"
Hope that helps
this sounds a lot like smartparens (https://github.com/Fuco1/smartparens) which is included in Prelude. usually when you are inside "" then it will escape the quotes:
"hahah \"\" bah"
if you want to get a normal " inside quotes you have to use C-q " or disable smartparens with M-x smartparens-mode
If, as you say in a comment, " is bound to self-insert-command, then when you type " what happens is that a (single, unescaped) " character is inserted.
However, I suspect you have some mode turned on that does something additional whenever a " char is inserted. You mention automatic insertion of a second ", for example. That kind of behavior comes from a mode such as is provided by library smart-parens or electric-pair.
And you mention Prelude.
To find out what part of your init file (~/.emacs) is causing the behavior you see, bisect your init file recursively (first comment-out half, to see which half is responsible, then 3/4, to see which quarter is responsible,...). Then, if you still have a question about the responsible code, ask here, providing that info.
When you describe your problem here, it is important to be specific: what Emacs version, what mode(s), what libraries have you loaded,... Whatever might be pertinent. But first narrow down the problem by bisecting your init file to find the culprit.

Emacs Prelude, Smartparens, and OsX

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.

Why isn't return bound to newline-and-indent by default on emacs

I have tried emacs on and off for a while now and every time I start emacs, I go through the same routine. Customizing. The first one is binding return to newline-and-indent. (g)Vim does this by default. Showing matching parenthesis is also done by default on (g)Vim. It is grea that I can customize emacs to my heart's content but why doesn't emacs have nice and easy defaults? For reference, I am now using Emacs 23 on a RHEL5 box.
Probably because RMS didn't want it, that and because changing long-standing defaults is just an issue of politics. Like vi, Emacs has a hard-core following and basic changes like these are minefields.
Note: if you saved your customizations, then you wouldn't have to re-do them every time...
To have those nice and easy defaults, install Emacs Starter Kit. It enables by default a bunch of useful and convenient features make even the advanced Emacs users more productive.
Otherwise, as TJ pointed out, Emacs Customization Mode (type M-x customize) allows you to save permanently any of the settings. You can even store them in a separate file from your dotemacs―(setq custom-file "~/.emacs-custom.el")―so you can use it in every computer you work on.
The title of your question doesn't really reflect what your question is (and has been answered by Trey and Torok), but I'll tell you why I like it being bound to just newline: useless whitespace. Say you are nested inside a conditional in a function etc. and hit return a couple times to leave a blank line. The blank line now has a bunch of space chars on it. Yes, you can (and I do) remove trailing whitespace before saving, but I also have visual whitespace mode on and I can see it there taunting me.