nim-lang / nim-mode

An emacs major mode for the Nim programming language
139 stars 46 forks source link

Cycle through different possible indent positions #78

Closed larme closed 8 years ago

larme commented 8 years ago

In python mode I can cycle through different possible indent positions by pressing tab repeatedly. Seems cannot do so in nim-mode.

yuutayamada commented 8 years ago

Hi @larme can you make sure your tab key's function?

currently the cycle feature can only apply specific functions: indent-for-tab-command, yas-expand, and yas/expand.

But also you can add your own:

(add-to-list 'nim-indent-trigger-commands
             'your-using-function-name)

If you wouldn't write specific function name, here is a way to add global-map's tab key function:

(add-to-list 'nim-indent-trigger-commands
             (lookup-key global-map (kbd "TAB")))

note that the function-name part has to be symbol (I mean you can't use lambda form)

larme commented 8 years ago

Hi @yuutayamada ,

Thanks for your quick reply. However, what I mean is not to cycle through several functions, but several indent positions.

Below is an example:

if a > 0:
  echo "positive"
else:
  echo "zero"

echo "finished"

When I press tab at the last line, I want the indent position to cycle between two positions:

if a > 0:
  echo "positive"
else:
  echo "zero"

echo "finished"

and

if a > 0:
  echo "positive"
else:
  echo "zero"

  echo "finished"
yuutayamada commented 8 years ago

Ah, now I understood your problem. Please add following configuration

(add-hook 'nim-mode-hook
          (lambda () (setq nim-smie-indent-stoppers nil
                           nim-smie-indent-dedenters nil)))

There is two variable that change indent behavior after empty line.

yuutayamada commented 8 years ago

@larme just FYI, nim-mode already has ability to cycle indent positions because most nim-mode's code was copied from python.el and what I thought at my first reply was you changed TAB key's default function. Since the indent cycle feature only apply default tab key's function and few other functions. (actually for yanippet.el)

yuutayamada commented 8 years ago

I'm closing this issue because of long term no reaction. Please re-open or make new issue if you have the problem.