Up to higher level directory | |||
Name | Date | Size | |
---|---|---|---|
pre-commit.sh | 22-Oct-2020 | 2.5K | |
README.rst | 22-Oct-2020 | 2.9K | |
vim/ | 22-Oct-2020 |
1 =========== 2 IDE Plugins 3 =========== 4 5 Emacs 6 ===== 7 8 The ``Emacs`` plugin is maintained separately. Installation directions can be 9 found here: https://github.com/paetzke/py-yapf.el 10 11 VIM 12 === 13 14 The ``vim`` plugin allows you to reformat a range of code. Copy ``plugin`` and 15 ``autoload`` directories into your ~/.vim or use ``:packadd`` in Vim 8. Or use 16 a plugin manager like Plug or Vundle: 17 18 .. code-block:: vim 19 20 " Plug 21 Plug 'google/yapf', { 'rtp': 'plugins/vim', 'for': 'python' } 22 23 " Vundle 24 Plugin 'google/yapf', { 'rtp': 'plugins/vim' } 25 26 27 You can add key bindings in the ``.vimrc`` file: 28 29 .. code-block:: vim 30 31 map <C-Y> :call yapf#YAPF()<cr> 32 imap <C-Y> <c-o>:call yapf#YAPF()<cr> 33 34 Alternatively, you can call the command ``YAPF``. If you omit the range, it 35 will reformat the whole buffer. 36 37 example: 38 39 .. code-block:: vim 40 41 :YAPF " formats whole buffer 42 :'<,'>YAPF " formats lines selected in visual mode 43 44 Sublime Text 45 ============ 46 47 The ``Sublime Text`` plugin is also maintained separately. It is compatible 48 with both Sublime Text 2 and 3. 49 50 The plugin can be easily installed by using *Sublime Package Control*. Check 51 the project page of the plugin for more information: 52 https://github.com/jason-kane/PyYapf 53 54 =================== 55 git Pre-Commit Hook 56 =================== 57 58 The ``git`` pre-commit hook automatically formats your Python files before they 59 are committed to your local repository. Any changes ``yapf`` makes to the files 60 will stay unstaged so that you can diff them manually. 61 62 To install, simply download the raw file and copy it into your git hooks 63 directory: 64 65 .. code-block:: bash 66 67 # From the root of your git project. 68 curl -o pre-commit.sh https://raw.githubusercontent.com/google/yapf/master/plugins/pre-commit.sh 69 chmod a+x pre-commit.sh 70 mv pre-commit.sh .git/hooks/pre-commit 71 72 ========== 73 Textmate 2 74 ========== 75 76 Plugin for ``Textmate 2`` requires ``yapf`` Python package installed on your 77 system: 78 79 .. code-block:: shell 80 81 pip install yapf 82 83 Also, you will need to activate ``Python`` bundle from ``Preferences >> 84 Bundles``. 85 86 Finally, create a ``~/Library/Application 87 Support/TextMate/Bundles/Python.tmbundle/Commands/YAPF.tmCommand`` file with 88 the following content: 89 90 .. code-block:: xml 91 92 <?xml version="1.0" encoding="UTF-8"?> 93 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 94 <plist version="1.0"> 95 <dict> 96 <key>beforeRunningCommand</key> 97 <string>saveActiveFile</string> 98 <key>command</key> 99 <string>#!/bin/bash 100 101 TPY=${TM_PYTHON:-python} 102 103 "$TPY" "/usr/local/bin/yapf" "$TM_FILEPATH"</string> 104 <key>input</key> 105 <string>document</string> 106 <key>name</key> 107 <string>YAPF</string> 108 <key>scope</key> 109 <string>source.python</string> 110 <key>uuid</key> 111 <string>297D5A82-2616-4950-9905-BD2D1C94D2D4</string> 112 </dict> 113 </plist> 114 115 You will see a new menu item ``Bundles > Python > YAPF``. 116