├── CONTRIBUTING.md ├── LICENSE ├── PATENTS ├── README.md └── flow.el /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to flow-for-emacs 2 | 3 | We want to make contributing to this project as easy and transparent as 4 | possible. 5 | 6 | ## Our Development Process 7 | 8 | The majority of development on flow-for-emacs will occur through 9 | GitHub. Accordingly, the process for contributing will follow standard GitHub 10 | protocol. 11 | 12 | ## Pull Requests 13 | 14 | We actively welcome your pull requests. 15 | 16 | 1. Fork the repo and create your branch from `master`. 17 | 2. If you've changed APIs, update the documentation. 18 | 3. If you haven't already, complete the Contributor License Agreement ("CLA"). 19 | 20 | ## Contributor License Agreement ("CLA") 21 | 22 | In order to accept your pull request, we need you to submit a CLA. You only need 23 | to do this once to work on any of Facebook's open source projects. 24 | 25 | Complete your CLA here: 26 | 27 | ## Issues 28 | 29 | We use GitHub issues to track public bugs. Please ensure your description is 30 | clear and has sufficient instructions to be able to reproduce the issue. 31 | 32 | Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe 33 | disclosure of security bugs. In those cases, please go through the process 34 | outlined on that page and do not file a public issue. 35 | 36 | ## Coding Style 37 | 38 | * 2 spaces for indentation rather than tabs 39 | * 80 character line length 40 | 41 | ## License 42 | 43 | By contributing to flow-for-emacs, you agree that your contributions will be 44 | licensed under its BSD license. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD License 2 | 3 | For flow-for-emacs software 4 | 5 | Copyright (c) 2016-present, Facebook, Inc. All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without modification, 8 | are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | * Neither the name Facebook nor the names of its contributors may be used to 18 | endorse or promote products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 25 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 28 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /PATENTS: -------------------------------------------------------------------------------- 1 | Additional Grant of Patent Rights Version 2 2 | 3 | "Software" means the flow-for-emacs software distributed by Facebook, Inc. 4 | 5 | Facebook, Inc. ("Facebook") hereby grants to each recipient of the Software 6 | ("you") a perpetual, worldwide, royalty-free, non-exclusive, irrevocable 7 | (subject to the termination provision below) license under any Necessary Claims, 8 | to make, have made, use, sell, offer to sell, import, and otherwise transfer the 9 | Software. For avoidance of doubt, no license is granted under Facebook?s rights 10 | in any patent claims that are infringed by (i) modifications to the Software 11 | made by you or any third party or (ii) the Software in combination with any 12 | software or other technology. 13 | 14 | The license granted hereunder will terminate, automatically and without notice, 15 | if you (or any of your subsidiaries, corporate affiliates or agents) initiate 16 | directly or indirectly, or take a direct financial interest in, any Patent 17 | Assertion: (i) against Facebook or any of its subsidiaries or corporate 18 | affiliates, (ii) against any party if such Patent Assertion arises in whole or 19 | in part from any software, technology, product or service of Facebook or any of 20 | its subsidiaries or corporate affiliates, or (iii) against any party relating to 21 | the Software. Notwithstanding the foregoing, if Facebook or any of its 22 | subsidiaries or corporate affiliates files a lawsuit alleging patent 23 | infringement against you in the first instance, and you respond by filing a 24 | patent infringement counterclaim in that lawsuit against that party that is 25 | unrelated to the Software, the license granted hereunder will not terminate 26 | under section (i) of this paragraph due to such counterclaim. 27 | 28 | A "Necessary Claim" is a claim of a patent owned by Facebook that is necessarily 29 | infringed by the Software standing alone. 30 | 31 | A "Patent Assertion" is any lawsuit or other action alleging direct, indirect, 32 | or contributory infringement or inducement to infringe any patent, including a 33 | cross-claim or counterclaim. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # flow-for-emacs 2 | 3 | **Archived**. We suggest using 4 | [an-sh/flow-minor-mode](https://github.com/an-sh/flow-minor-mode) instead. 5 | 6 | An emacs plugin for [Flow][flowtype], a static typechecker for 7 | JavaScript. 8 | 9 | [flowtype]: http://flowtype.org 10 | -------------------------------------------------------------------------------- /flow.el: -------------------------------------------------------------------------------- 1 | ;; 2 | ;; Copyright (c) 2016-present, Facebook, Inc. 3 | ;; All rights reserved. 4 | ;; 5 | ;; This source code is licensed under the BSD-style license found in the LICENSE 6 | ;; file in the root directory of this source tree. An additional grant of patent 7 | ;; rights can be found in the PATENTS file in the same directory. 8 | ;; 9 | 10 | (setq flow_binary "flow") 11 | 12 | (defun column-number-at-pos (pos) 13 | "column number at pos" 14 | (save-excursion (goto-char pos) (current-column)) 15 | ) 16 | 17 | (defun string-of-region () 18 | "string of region" 19 | (if (use-region-p) 20 | (let ((begin (region-beginning)) 21 | (end (region-end))) 22 | (format ":%d:%d,%d:%d" 23 | (line-number-at-pos begin) 24 | (column-number-at-pos begin) 25 | (line-number-at-pos end) 26 | (column-number-at-pos end))) 27 | "") 28 | ) 29 | 30 | (defun get-assoc-value (key alist) 31 | "get assoc value" 32 | (setq blah (assoc key alist)) 33 | (if blah 34 | (cdr blah) 35 | nil) 36 | ) 37 | 38 | (defun flow-start () 39 | (shell-command (format "%s start" flow_binary)) 40 | ) 41 | 42 | (defun flow-stop () 43 | (shell-command (format "%s stop" flow_binary)) 44 | ) 45 | 46 | (defun flow-status () 47 | "Initialize flow" 48 | (interactive) 49 | (flow-start) 50 | (compile (format "%s status --from emacs; exit 0" flow_binary)) 51 | ) 52 | 53 | (global-set-key (kbd "C-x C-m") 'flow-status) 54 | 55 | (defun flow-type-at-pos () 56 | "show type" 57 | (interactive) 58 | (let ((file (buffer-file-name)) 59 | (line (line-number-at-pos)) 60 | (col (current-column)) 61 | (buffer (current-buffer))) 62 | (switch-to-buffer-other-window "*Shell Command Output*") 63 | (flow-start) 64 | (shell-command 65 | (format "%s type-at-pos --from emacs %s %d %d" 66 | flow_binary 67 | file 68 | line 69 | (1+ col))) 70 | (compilation-mode) 71 | (switch-to-buffer-other-window buffer)) 72 | ) 73 | 74 | (global-set-key (kbd "C-c C-t") 'flow-type-at-pos) 75 | 76 | (defun flow-suggest () 77 | "fill types" 78 | (interactive) 79 | (let ((file (buffer-file-name)) 80 | (region (string-of-region)) 81 | (buffer (current-buffer))) 82 | (switch-to-buffer-other-window "*Shell Command Output*") 83 | (flow-start) 84 | (shell-command 85 | (format "%s suggest %s%s" 86 | flow_binary 87 | file 88 | region)) 89 | (compilation-mode) 90 | (switch-to-buffer-other-window buffer)) 91 | ) 92 | 93 | (global-set-key (kbd "C-t") 'flow-suggest) 94 | 95 | (defun flow-get-def () 96 | "jump to definition" 97 | (interactive) 98 | (let ((file (buffer-file-name)) 99 | (line (line-number-at-pos)) 100 | (col (current-column)) 101 | (buffer (current-buffer))) 102 | (switch-to-buffer-other-window "*Shell Command Output*") 103 | (flow-start) 104 | (shell-command 105 | (format "%s get-def --from emacs %s %d %d" 106 | flow_binary 107 | file 108 | line 109 | (1+ col))) 110 | (compilation-mode)) 111 | ) 112 | 113 | (global-set-key (kbd "M-.") 'flow-get-def) 114 | 115 | (defun flow-autocomplete () 116 | "autocomplete" 117 | (interactive) 118 | (let ((file (buffer-file-name)) 119 | (line (line-number-at-pos)) 120 | (col (current-column)) 121 | (buffer (current-buffer))) 122 | (switch-to-buffer-other-window "*Shell Command Output*") 123 | (flow-start) 124 | (shell-command 125 | (format "%s autocomplete %s %d %d < %s" 126 | flow_binary 127 | file 128 | line 129 | (1+ col) 130 | file)) 131 | (compilation-mode) 132 | (switch-to-buffer-other-window buffer)) 133 | ) 134 | 135 | (global-set-key (kbd "M-TAB") 'flow-autocomplete) 136 | 137 | (add-hook 'kill-emacs-hook 138 | (lambda () 139 | (flow-stop))) 140 | --------------------------------------------------------------------------------