Fork me on GitHub
#emacs
<
2018-01-14
>
vemv17:01:14

Given the following Clojure code:

(defn foo []
  (let [...]
  ;; <---- Cursor is here, column 3



)

vemv17:01:04

(blank lines are intended, as example)

vemv17:01:20

...if I press <down>, cursor would go from column 3 to column 0. I hate that, since current indentation level is at column 3. i.e I'm editing a let; I don't expect to be removed from that level

vemv17:01:36

so I have to press <tab> right after pressing <down>

vemv17:01:12

so I tried hacked a next-line replacement that executes indent-for-tab-command right after native next-line.

vemv17:01:15

works, but:

vemv17:01:20

- decreases performance

vemv17:01:19

- modifies the buffer (by inserting whitespace), so the buffer will become 'unsaved' easily

vemv17:01:54

wondering if anyone has felt the same pain / addressed it more robustly?

Macroz17:01:58

I don't generally have those empty lines there, but normally I just keep on typing whatever I'm doing and once in a while press C-tab to indent whole buffer. I don't bother with individual line problems

vemv17:01:42

I don't think we're talking about the same thing. I'm not talking about removing white lines. I'm talking about cursor column being moved to 0, even though its current 'semantic' level is nonzero

Macroz17:01:43

yes, I just told you that I have no such problem because I do not care about the indentation of incomplete code

Macroz17:01:56

or where the cursor is either

Macroz17:01:05

what is it that you are trying to achieve with this?

vemv17:01:10

ah gotchu, you just type misaligned code, given that it'll be reformatted. it's an approach 🙂 I wouldn't like that myself though

Macroz17:01:30

mind you, I don't use paredit which would enforce correctness

Macroz17:01:54

I used to have tab bound to indenting the whole buffer all the time but that was rather slow with big files

vemv17:01:39

trying to achieve: simply coding in a way that is aligned at almost-all times, and that doesn't require me to constantly hit <tab>

Macroz17:01:57

how do you end up with those blank lines in the first place?

Macroz17:01:47

enter indents the next line correctly, it is only the cursor movement down that moves to a blank line that moves the cursor to the last possible position

vemv17:01:28

I don't leave that many, but 1 or 2 on certain cases. for example dense fns benefit from blank lines for delimiting logical chunks

vemv17:01:13

or maybe I do insert many lines, knowing that I'm about to code a bunch of stuff

Macroz17:01:51

I do that too but since emacs remembers the cursor position you can just keep scrolling up or down and it returns to the correct position after the blank line

Macroz17:01:07

I never insert blank lines after

gonewest81818:01:55

You can press return which is usually configured to create a properly indented new line. And in my setup if I were to press ) at the place you’ve indicated, it would close the let and eliminate all the unnecessary blank lines. I never bothered to check, but I would guess paredit is taking care of that for me.

vemv18:01:28

return does that, but when you 'come back' with up/`down`, trailing whitespace will have disappeared

vemv18:01:54

note that I want, at the same time, to respect the convention of not leaving trailing whitespace (not that I like that convention; but gotta respect it)

vemv18:01:01

surely there's a tension between both goals. I reckon that what I want is a 'virtual whitespace grid', by which having the cursor at column N does not necessarily mean that there are N space characters in that line

vemv18:01:12

iirc, IntelliJ can do that

dpsutton18:01:41

my understanding is that this is a limitation of emacs. it does not work on a grid system but on a list of characters that forms the buffer.

dpsutton18:01:16

so you can't be at column 5 unless there are 4 characters preceding you

vemv18:01:36

sounds likely, thanks for the input!

bozhidar20:01:10

Yeah, that’s about right. You can’t be visiting a buffer location that doesn’t really exist.

benedek21:01:53

unless you are in picture mode 😉

benedek21:01:05

the freedom is amazing in picture mode