d12frosted / fish-mode

Major mode for editing fish shell scripts
1 stars 0 forks source link

indentation problem #2

Open c02y opened 9 years ago

c02y commented 9 years ago

This fixes the problem of indentation from https://github.com/wwwjfy/emacs-fish, so please upload this to melpa so I can install/update using package.el

c02y commented 9 years ago

It seems I made a wrong conclusion, it didn't fix my problem of indentation.

Put this in config.fish:

set -gx LESS_TERMCAP_me \e'[0m'     # turn off all appearance modes (mb, md, so, us)
set -gx LESS_TERMCAP_se \e'[0m'     # leave standout mode
set -gx LESS_TERMCAP_ue \e'[0m'     # leave underline mode
set -gx LESS_TERMCAP_so \e'[01;44m' # begin standout-mode – info
set -gx LESS_TERMCAP_mb \e'[01;31m' # enter blinking mode
set -gx LESS_TERMCAP_md \e'[01;38;5;75m' # enter double-bright mode
set -gx LESS_TERMCAP_us \e'[04;38;5;200m' # enter underline mode

You'll notice the problem of indentation after the second line of the snippet.

d12frosted commented 9 years ago

Sorry for late response - was in travel mode. My changes are part of emacs-fish. So it's expected that we have the same problems :smile:

But good thing - I am able to reproduce your issue and will update package soon. In short - the problem comes from the fact that begin is not ignored if it's inside of comment.

Thanks for the finding!

c02y commented 9 years ago

Thanks, you can close this.

c02y commented 9 years ago

I found that once delete one space in one comment line, the indention problem will be gone, the original code snippet:

set -gx LESS_TERMCAP_me \e'[0m'     # turn off all appearance modes (mb, md, so, us)
set -gx LESS_TERMCAP_se \e'[0m'     # leave standout mode
set -gx LESS_TERMCAP_ue \e'[0m'     # leave underline mode
set -gx LESS_TERMCAP_so \e'[01;44m' # begin standout-mode – info
set -gx LESS_TERMCAP_mb \e'[01;31m' # enter blinking mode
set -gx LESS_TERMCAP_md \e'[01;38;5;75m' # enter double-bright mode
set -gx LESS_TERMCAP_us \e'[04;38;5;200m' # enter underline mode

the indention of all the lines after the 4th line will be wrong. if I change the 4th line to:

set -gx LESS_TERMCAP_so \e'[01;44m' #begin standout-mode – info

Note the deleted space before begin, then the indentation will be normal.

d12frosted commented 9 years ago

Note the deleted space before begin, then the indentation will be normal.

Yeah, it's because of how special keywords are parsed. Fish-mode doesn't treat #begin the same way as begin.

P. S. Sorry for solving this issue for so long.

c02y commented 9 years ago

The indentation problem is still there.

Note that I didn't use

(add-hook 'fish-mode-hook (lambda ()
                        (add-hook 'before-save-hook 'fish_indent-before-save)))

in my init.el, I got my own indent-buffer(basciall I use (indent-region (point-min) (point-max) for this function) before-save-hook, it will not work perfectly (I'll explain later) even I put your two lines, the point or the window will jump around several lines after saving the buffer, the problem is the fish_indent function of your code. I can put several lines of code inside my before-save-hook or totally comment my part out and use yours for fish-mode file to make indentation right, but it is not perfect thought (I'll explain later), and I feel ridiculous to add several lines of code or your yours code for just fish-mode file .


Another problem is this single line in my conf.fish:

alias tt 'tmux switch-client -t'

will make the indentation of all the lines after this line wrong, exactly like the indentation I mentioned about the # begin earlier. I cannot figure out what is the problem of that line, if I comment it out, the problem will go wrong.

As for the # begin problem, even thought I make #begin, the updated fish-mode source code will not fix it any more, it seems the two bugs were made after I finally found the solution (make it #begin), right now I just deleted the begin word and put the alias line at the end of my conf.fish file to make it right, maybe because I use my own indent-buffer before-save-hook instead of the two lines of code you recommended.

Any way, you should not define another function to indent the fish-mode file, just let my (indent-region (point-min) (point-max) do the work.

d12frosted commented 9 years ago

Thanks for posting more information about problems with indentation. Actually, your cases show that current implementation is easily broken and far from ideal.

Sorry for not fixing those problems. I am not sure when, but I'll try to fix them soon.