![]() ![]() "Print number of non-trivial matches for REGEXP in region. I put the following code in my init.el (.emacs) file: (defun how-many-region (begin end regexp &optional interactive) Putting that code in my init.el file (and those last 2 lines in my python-mode-hook) got Emacs to know whether tabs or spaces were being used. I feel kind of ridiculous for not having seen this before, but I found the answer on the EmacsWiki: No Tabs page under the "Smart inference of indentation style" section. This will only use spaces in Python files. ![]() I've also tried the following: (add-hook 'python-mode-hook 'guess-style-guess-tabs-mode) Setting it to nil makes it always use spaces. Setting indent-tabs-mode to t makes it always use a tab character. I've been messing around with the following: (add-hook 'python-mode-hook I've also tried this with a blank init file and having only the modifications to tab. ![]() I am using Elpy, but I've tried this with Elpy disabled. I can't get Emacs to recognize the difference. All the lines of code that come under a particular indent belong to the clause before the indent. An indent provides space or tab which also provides an increase in readability. Some cases where we need to use indentation and might get. An indent in python is where the block of code belonging to a clause starts. The Python code needs to be indented in some cases where one part of the code needs to be written in a block. ![]() Indentation can be done in Python using either spaces or the tab button choosing which one depends entirely on the user. In one file, that indent is using 4 spaces while the other file uses a tab character. Indentation also increases the readability of the code. I created 2 simple files consisting of: a = 1 I know I can just untabify everything, but this might not be an option when working on someone else's code and they'd like to use tabs instead (for whatever reason). I'd like to leave it at using spaces by default, but recognize when tab characters are used and use that instead (for my older python files). I also know how to get it to use the tab character by default. py files, I know how to get emacs to use 4 spaces as an indent by default. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |