Configure python hanging indent after an open parenthesis - emacs

Emacs indents my code like this:
def my_function(
a, b, c):
pass
if my_function(
1, 2, 3):
pass
However, PEP8 states that it should be indented like this, to avoid confusing the hanging indent with the next line:
def my_function(
a, b, c):
pass
if my_function(
1, 2, 3):
pass
How can I configure emacs' old python.el to use the existing python-continuation-offset variable in this case (after an opening parenthesis and newline), so as to indent the second way?

Just for information, Python mode in GNU Emacs 25 formats this correctly.

Related

Emacs Pretty Symbols in cperl mode: :: must be surrounded my spaces

I'm using Emacs with PDE and cperl-mode. I really want prettify-symbols-mode to work with it. When just using perl-mode this happens:
Mod::thing->new( {c => 'sea'} );
becomes
Mod∷thing→new( {c ⇒ 'sea'} );
however when using cperl same expression becomes
Mod::thing→new( {c ⇒ 'sea'} );
in cperl-mode the :: only becomes ∷ when it is separated by spaces on both sides.
I have tried adding to the cperl--pretty-symbols-alist and pretty-symbols-alist. and still only the -> and => work.
I thought it might be how cperl defines characters as symbols or words, but the -> and => work just fine without being surrounded by spaces.
I got it. I went to /usr/share/emacs/26.1/lisp/progmodes and deleted a file called cperl-mode.elc. then I went into an archinve here /usr/share/emacs/26.1/lisp/progmodes/cperl-mode.el.gz. I edited line 1498 of cperl-mode.el to be (modify-syntax-entry ?: "." cperl-mode-syntax-table) instead of (modify-syntax-entry ?: "_" cperl-mode-syntax-table). Then I byte-compiled the file and put it back in /usr/share/emacs/26.1/lisp/progmodes.
You can also do this in your init file so you don't have to edit any files that are shipped with Emacs. If you edit files that are part of Emacs, you'll need to update them every time you install or upgrade.
(with-eval-after-load "cperl-mode"
(modify-syntax-entry ?: "." cperl-mode-syntax-table))

How to list out previous command arguments input to minibuffer in Emacs?

Often I need to do replacement with text. I am looking for a way to avoid repeatedly input replacement text.
For example, firstly, I replaced a with b in text;
Secondly, I replaced c with d.
Thirdly, I need to replace a with b again. However, Emacs only store last replacement as default argument.
What is the way to list previous replacement argument, i.e. a to b?
The responses you give to M-% (and other commands that get input from the minibuffer) are kept in the history. Hit the "Up" key to see them.
As the search texts and the replacement texts are kept in the same history, in your case above the history would be a, b, c, d. So, when prompted for the search text, you'd need to hit "Up" four times to come back to a. The history would then change to a, b, c, d, a, so to get back to b as replacement text you'd again need to hit "Up" four times.
You can use M-p instead of "Up" if you prefer.
If you want to see what the previous minibuffer values were without invoking another command you can directly inspect the minibuffer-history variable: C-h v minibuffer-history. This will list all of the values together with the description of this variable.

How can I htmlfontify an Emacs buffer with composed characters preserved?

How can I htmlfontify a code buffer in Emacs without losing the composed characters?
I have several modes that display certain ASCII sequences as unicode using compose-region. For example, I might write something like:
foo :: Num a => [a] -> a
foo = foldl (+) 0 . map (\ x -> x + f x - 10)
and the editor displays (without changing the buffer's actual contents):
foo ∷ Num a ⇒ [a] → a
foo = foldl (+) 0 ∘ map (λ x → x + f x - 10)
This is essentially another form of syntax highlighting, except with special characters instead of colors.
However, when I use M-x htmlfontify-buffer on a buffer that looks like my second example, all this information is lost and the html output looks like the first version. How can I avoid losing the character transformations?
I don't think htmlfontify supports this feature yet. But if you M-x report-emacs-bug to request the feature, you might find someone who can implement it fairly quickly (then again, maybe not).

How to modify previous line in REPL - scala to modify the typing errors to save time compare to entering each line using up/down arrows

There are chances that some typing (in Ubuntu terminal - scala -version
Scala code runner version 2.9.1) errors occur, example shown below where instead of (l: Int) (l: int) has been typed in parameters.
scala> class Rectangle (l:int, w: Int){
| val length = l
| val length = w
.
.
.
few more lines but still ... module Rectangle is not defined. Or sometimes enter command given and error shows up.
Is there anyway where directly that typing error can be edited / modified and rerun the code? It will save great deal of time otherwise I am entering line by line using up/down arrow.
Please guide.
I don't know if there is a better solution, but in my case I tend to use my usual text editor to write code snippet and paste them using the paste mode of the REPL (you can enter the paste mode thanks to the :paste command).
Right now, you can't. There are Scala GUI REPL's (see them here, plus kojo and the big IDEs), though, which allow this kind of thing. Pick one of them.
Since Scala 2.13.2 multi-line editing is supported in the REPL based on JLine 3
JLine 3 supports multi-line editing, a better tab-completion UI, and
more.
Configure keybindings with -Xjline:emacs (the default) or -Xjline:vi;
disable with -Xjline:off
History file is now ~/.scala_history_jline3
For example, to try multiline editing using vim keybindings start the REPL like so
scala -Xjline:vi
then enter a multiline definition and press up arrow key. Note how it gives
scala> class Foo {
| val x = 42
| }
class Foo
scala> class Foo {
| val x = 42
| }
instead of the old behaviour
scala> class Foo {
| val x = 42
| }
defined class Foo
scala> }

Indenting template arguments in Emacs

I'm having no luck getting Emacs (cc-mode) to indent multiline template arguments. Here's an example line:
typedef ::boost::zip_iterator< ::boost::tuple<
vector<int>::const_iterator, vector<float>::const_iterator > >;
I'd like the second line to be indented, as like in a function. It is indented, until I enter the second-to-last >, at which point the second line up moves to the left to align with the typedef.
When I start typing the second line, the syntactic analysis is ((statement-cont 52)), until the second-to-last >, at which point it becomes ((defun-block-intro 46)). Deleting the character doesn't return to the old syntactic analysis.
I expected to have template-args-cont as the syntactic analysis.
I'm using the emacs 22.2 (ubuntu intrepid) and cc-mode version 5.31.5 that came with it.
You should just need to set template-args-cont to some useful value. To experiment with it, put your cursor on the second line and enter C-cC-o for c-set-offset. Insert a convenient value. With 4, I get:
typedef ::boost::zip_iterator< ::boost::tuple<
vector<int>::const_iterator, vector<float>::const_iterator > >;
If that doesn't work, check your version: I have cc-mode version 5.31.6. To check, do M-x c-version. I get
Using CC Mode version 5.31.6