├── .gitignore ├── COPYING ├── README.md ├── TODO ├── pry.el └── ruby ├── emacs_pry.rb └── monkey_patch_require.rb /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | \.\#* 3 | \#* -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Emacs Pry 2 | 3 | * Git: http://github.com/jacott/emacs-pry 4 | * Author: Geoff Jacobsen 5 | * Copyright: 2012 6 | * License: GNU GPLv3 7 | 8 | ### Description 9 | 10 | Emacs Pry is package that provides support for running [Pry](https://github.com/pry/pry) within in Emacs. 11 | 12 | ### Features 13 | 14 | `run-pry` starts a Pry REPL inside a modified `term-mode` buffer. 15 | 16 | `pry-intercept` command allows for quick debuging into a test without needing to write the `binding.pry` into the file. 17 | 18 | Automatically shows source in emacs buffer. 19 | 20 | You can use the pointer or other emacs commands to move the cursor on the command line and Pry will be aligned with the new position. 21 | 22 | ### Install 23 | 24 | Ensure you are running ruby 1.9.3 or later 25 | 26 | ```sh 27 | gem install pry 28 | mkdir -p ~/.emacs.d/vendor 29 | cd ~/.emacs.d/vendor 30 | git clone git@github.com:jacott/emacs-pry 31 | ``` 32 | 33 | Add the following to your `.emacs` or `.emacs.d/init.el` file 34 | 35 | ```lisp 36 | (add-to-list 'load-path "~/.emacs.d/vendor/emacs-pry") 37 | (require 'pry) 38 | ;; optional suggestions 39 | (global-set-key [S-f9] 'pry-intercept) 40 | (global-set-key [f9] 'pry-intercept-rerun) 41 | ``` 42 | 43 | ### Optional 44 | 45 | * `gem install pry-nav pry-stack_explorer` 46 | * `gem install termios # replaces the running of: stty sane` 47 | 48 | * https://github.com/jacott/Enhanced-Ruby-Mode 49 | 50 | ### Thanks 51 | 52 | https://github.com/banister for the Pry gem! -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | 2 | * Make key-maps change depending on cursor location to command prompt. 3 | 4 | * Better spliting of shell arglist strings to list/array 5 | 6 | * Breakpoint in pry 7 | Use buffer properties to mark; add symbol like gdb 8 | 9 | * require_relative interception support for pry 10 | And load support? 11 | 12 | * Exception highlighting and clickable 13 | 14 | * Customize pryrc loading: nil, t, string 15 | 16 | * Eval exp in pry 17 | Send the current sexp to the *pry* buffer for evalulation. 18 | Do a "!\n" if pry-input not empty - look at proccess-mark, and displayed prompt to determine. 19 | 20 | 21 | 22 | DONE 23 | 24 | * Re-aligning process-mark with point using left and right if on input line. 25 | 26 | * Auto whereami buffer viewing 27 | Visit one and only one buffer unless buffer already open but always move to point 28 | 29 | -------------------------------------------------------------------------------- /pry.el: -------------------------------------------------------------------------------- 1 | ;;; pry.el --- Interaction with the ruby pry command 2 | 3 | ;; Copyright (C) 2010, 2011, 2012 4 | ;; Geoff Jacobsen 5 | 6 | ;; Author: Geoff Jacobsen 7 | ;; URL: http://http://github.com/jacott/emacs-pry 8 | ;; Created: Sep 18 2010 9 | ;; Keywords: languages elisp, ruby 10 | ;; Version: 0.1 11 | 12 | ;; This file is not part of GNU Emacs. 13 | 14 | ;; This file is free software: you can redistribute it and/or modify 15 | ;; it under the terms of the GNU General Public License as published by 16 | ;; the Free Software Foundation, either version 2 of the License, or 17 | ;; (at your option) any later version. 18 | 19 | ;; It is distributed in the hope that it will be useful, but WITHOUT 20 | ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 21 | ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 22 | ;; License for more details. 23 | 24 | ;; You should have received a copy of the GNU General Public License 25 | ;; along with it. If not, see . 26 | 27 | ;;; Commentary: 28 | 29 | (require 'term) 30 | 31 | ;; override standard term func 32 | ;; (defun term-handle-ansi-escape (proc char) 33 | ;; (cond 34 | ;; ((or (eq char ?H) ;; cursor motion (terminfo: cup,home) 35 | ;; ;; (eq char ?f) ;; xterm seems to handle this sequence too, not 36 | ;; ;; needed for now 37 | ;; ) 38 | ;; (when (<= term-terminal-parameter 0) 39 | ;; (setq term-terminal-parameter 1)) 40 | ;; (when (<= term-terminal-previous-parameter 0) 41 | ;; (setq term-terminal-previous-parameter 1)) 42 | ;; (when (> term-terminal-previous-parameter term-height) 43 | ;; (setq term-terminal-previous-parameter term-height)) 44 | ;; (when (> term-terminal-parameter term-width) 45 | ;; (setq term-terminal-parameter term-width)) 46 | ;; (term-goto 47 | ;; (1- term-terminal-previous-parameter) 48 | ;; (1- term-terminal-parameter))) 49 | ;; ;; \E[A - cursor up (terminfo: cuu, cuu1) 50 | ;; ((eq char ?A) 51 | ;; (term-handle-deferred-scroll) 52 | ;; (let ((tcr (term-current-row))) 53 | ;; (term-down 54 | ;; (if (< (- tcr term-terminal-parameter) term-scroll-start) 55 | ;; ;; If the amount to move is before scroll start, move 56 | ;; ;; to scroll start. 57 | ;; (- term-scroll-start tcr) 58 | ;; (if (>= term-terminal-parameter tcr) 59 | ;; (- tcr) 60 | ;; (- (max 1 term-terminal-parameter)))) t))) 61 | ;; ;; \E[B - cursor down (terminfo: cud) 62 | ;; ((eq char ?B) 63 | ;; (let ((tcr (term-current-row))) 64 | ;; (unless (= tcr (1- term-scroll-end)) 65 | ;; (term-down 66 | ;; (if (> (+ tcr term-terminal-parameter) term-scroll-end) 67 | ;; (- term-scroll-end 1 tcr) 68 | ;; (max 1 term-terminal-parameter)) t)))) 69 | ;; ;; \E[C - cursor right (terminfo: cuf, cuf1) 70 | ;; ((eq char ?C) 71 | ;; (term-move-columns 72 | ;; (max 1 73 | ;; (if (>= (+ term-terminal-parameter (term-current-column)) term-width) 74 | ;; (- term-width (term-current-column) 1) 75 | ;; term-terminal-parameter)))) 76 | ;; ;; \E[D - cursor left (terminfo: cub) 77 | ;; ((eq char ?D) 78 | ;; (term-move-columns (- (max 1 term-terminal-parameter)))) 79 | ;; ;; \E[G - pry added not handled by term.el 80 | ;; ((eq char ?G) 81 | ;; (forward-line term-terminal-parameter)) 82 | ;; ;; \E[J - clear to end of screen (terminfo: ed, clear) 83 | ;; ((eq char ?J) 84 | ;; (term-erase-in-display term-terminal-parameter)) 85 | ;; ;; \E[K - clear to end of line (terminfo: el, el1) 86 | ;; ((eq char ?K) 87 | ;; (term-erase-in-line term-terminal-parameter)) 88 | ;; ;; \E[L - insert lines (terminfo: il, il1) 89 | ;; ((eq char ?L) 90 | ;; (term-insert-lines (max 1 term-terminal-parameter))) 91 | ;; ;; \E[M - delete lines (terminfo: dl, dl1) 92 | ;; ((eq char ?M) 93 | ;; (term-delete-lines (max 1 term-terminal-parameter))) 94 | ;; ;; \E[P - delete chars (terminfo: dch, dch1) 95 | ;; ((eq char ?P) 96 | ;; (term-delete-chars (max 1 term-terminal-parameter))) 97 | ;; ;; \E[@ - insert spaces (terminfo: ich) 98 | ;; ((eq char ?@) 99 | ;; (term-insert-spaces (max 1 term-terminal-parameter))) 100 | ;; ;; \E[?h - DEC Private Mode Set 101 | ;; ((eq char ?h) 102 | ;; (cond ((eq term-terminal-parameter 4) ;; (terminfo: smir) 103 | ;; (setq term-insert-mode t)) 104 | ;; ;; ((eq term-terminal-parameter 47) ;; (terminfo: smcup) 105 | ;; ;; (term-switch-to-alternate-sub-buffer t)) 106 | ;; )) 107 | ;; ;; \E[?l - DEC Private Mode Reset 108 | ;; ((eq char ?l) 109 | ;; (cond ((eq term-terminal-parameter 4) ;; (terminfo: rmir) 110 | ;; (setq term-insert-mode nil)) 111 | ;; ;; ((eq term-terminal-parameter 47) ;; (terminfo: rmcup) 112 | ;; ;; (term-switch-to-alternate-sub-buffer nil)) 113 | ;; )) 114 | 115 | ;; ;; Modified to allow ansi coloring -mm 116 | ;; ;; \E[m - Set/reset modes, set bg/fg 117 | ;; ;;(terminfo: smso,rmso,smul,rmul,rev,bold,sgr0,invis,op,setab,setaf) 118 | ;; ((eq char ?m) 119 | ;; (when (= term-terminal-more-parameters 1) 120 | ;; (when (>= term-terminal-previous-parameter-4 0) 121 | ;; (term-handle-colors-array term-terminal-previous-parameter-4)) 122 | ;; (when (>= term-terminal-previous-parameter-3 0) 123 | ;; (term-handle-colors-array term-terminal-previous-parameter-3)) 124 | ;; (when (>= term-terminal-previous-parameter-2 0) 125 | ;; (term-handle-colors-array term-terminal-previous-parameter-2)) 126 | ;; (term-handle-colors-array term-terminal-previous-parameter)) 127 | ;; (term-handle-colors-array term-terminal-parameter)) 128 | 129 | ;; ;; \E[6n - Report cursor position (terminfo: u7) 130 | ;; ((eq char ?n) 131 | ;; (term-handle-deferred-scroll) 132 | ;; (process-send-string proc 133 | ;; ;; (terminfo: u6) 134 | ;; (format "\e[%s;%sR" 135 | ;; (1+ (term-current-row)) 136 | ;; (1+ (term-horizontal-column))))) 137 | ;; ;; \E[r - Set scrolling region (terminfo: csr) 138 | ;; ((eq char ?r) 139 | ;; (term-set-scroll-region 140 | ;; (1- term-terminal-previous-parameter) 141 | ;; (1- term-terminal-parameter))) 142 | ;; (t))) 143 | 144 | (defcustom pry-program-name "pry" 145 | "Program invoked by the `run-pry' command." 146 | :group 'eri) 147 | 148 | (defvar pry-raw-map nil "Keymap used in pry mode.") 149 | 150 | (defvar pry-intercept-command nil "Keymap used in pry mode.") 151 | 152 | (defvar pry-target-mark nil "Last target of pry-intercept.") 153 | 154 | (defvar pry-cursor-overlay nil "Overlay for process-mark location using `vcursor' face") 155 | (defvar pry-last-prompt (make-marker) "position of last displayed prompt") 156 | (set-marker-insertion-type pry-last-prompt nil) 157 | 158 | (defvar pry-source-location-regexp "^From: \\(.*\\.rb\\) @ line \\([0-9]+\\)" "Source location regular expression") 159 | (defvar pry-whereami (make-marker) "Location of last pry location") 160 | 161 | (if pry-raw-map 162 | nil 163 | (setq pry-raw-map (copy-keymap term-raw-map)) 164 | (define-key pry-raw-map [remap self-insert-command] 'pry-send-raw) 165 | (define-key pry-raw-map [remap term-send-raw] 'pry-send-raw) 166 | (define-key pry-raw-map [remap term-send-right] 'pry-send-right) 167 | (define-key pry-raw-map [remap term-send-left] 'pry-send-left) 168 | (define-key pry-raw-map [remap term-send-del] 'pry-send-del) 169 | (define-key pry-raw-map [remap term-send-backspace] 'pry-send-backspace) 170 | (define-key pry-raw-map [remap term-send-raw-meta] 'pry-send-raw-meta) 171 | (define-key pry-raw-map "\C-x" 'Control-X-prefix) 172 | (define-key pry-raw-map "\M-x" 'execute-extended-command)) 173 | 174 | 175 | 176 | (defun run-pry (cmd) 177 | "Run an inferior Pry process, input and output via buffer *pry*. 178 | If there is a process already running in `*pry*', switch to that buffer. 179 | With argument, allows you to edit the command line (default is value 180 | of `pry-program-name'). 181 | \(See `pry-mode' for a list of commands.)" 182 | 183 | (interactive (list (if current-prefix-arg 184 | (read-string "Run Pry: " pry-program-name) 185 | pry-program-name))) 186 | 187 | 188 | 189 | (with-current-buffer (get-buffer-create "*pry*") 190 | (let ((proc (get-buffer-process (current-buffer)))) 191 | (unless (and proc (equal (process-status proc) 'run)) 192 | (let* ((cmdlist (split-string cmd)) 193 | (process-connection-type t) 194 | ;; We should suppress conversion of end-of-line format. 195 | (inhibit-eol-conversion t) 196 | ;; The process's output contains not just chars but also binary 197 | ;; escape codes, so we need to see the raw output. We will have to 198 | ;; do the decoding by hand on the parts that are made of chars. 199 | (coding-system-for-read 'binary)) 200 | (if (string= pry-program-name cmd) 201 | (setq cmdlist (apply 'list (car cmdlist) (concat "-r" (pry-source-dir) "ruby/emacs_pry.rb") (cdr cmdlist)))) 202 | 203 | 204 | 205 | (setq proc (apply 'start-process "inferior-pry-process" 206 | (current-buffer) 207 | (car cmdlist) 208 | (cdr cmdlist))) 209 | (set-process-sentinel proc 'pry-process-sentinel) 210 | (set-process-query-on-exit-flag proc nil) 211 | (pry-setup-buffer proc) 212 | (set-process-filter proc 'pry-filter))) 213 | 214 | (pop-to-buffer (current-buffer)) 215 | proc))) 216 | 217 | (defun pry-setup-buffer (proc) 218 | (pry-mode) 219 | (goto-char (point-max)) 220 | (set-marker (process-mark proc) (point)) 221 | (term-char-mode) 222 | (set-process-coding-system proc 'binary 'binary)) 223 | 224 | 225 | (defun pry-process-sentinel (proc msg) 226 | ; (when (eq (current-buffer) (get-buffer "*pry*")) 227 | (when (memq (process-status proc) '(exit signal)) 228 | (term-line-mode)) 229 | (insert msg)) 230 | 231 | 232 | (defun pry-filter (proc response) 233 | (with-current-buffer (process-buffer proc) 234 | (let ((buffer-read-only nil) 235 | (buffer-undo-list t)) 236 | (term-emulate-terminal proc response)) 237 | (pry-search-for-source))) 238 | 239 | (defun pry-select-file (file line) 240 | (with-selected-window (selected-window) 241 | (let* ((file (expand-file-name file)) 242 | (newbuf (find-buffer-visiting file)) 243 | (oldbuf (marker-buffer pry-whereami)) 244 | view-window) 245 | 246 | 247 | (when oldbuf 248 | (when (setq view-window (get-buffer-window oldbuf)) 249 | (select-window view-window))) 250 | 251 | (if newbuf 252 | (unless view-window 253 | (if (get-buffer-window newbuf) 254 | (select-window (get-buffer-window newbuf)) 255 | (switch-to-buffer-other-window newbuf))) 256 | 257 | (if view-window 258 | (view-file file) 259 | (view-file-other-window file)) 260 | (setq newbuf (current-buffer))) 261 | 262 | (when (and oldbuf (not (eq oldbuf newbuf))) 263 | (with-current-buffer oldbuf 264 | (when view-mode 265 | (View-quit)))) 266 | 267 | (with-current-buffer newbuf 268 | (goto-char (point-min)) 269 | (forward-line (1- line)) 270 | (move-marker pry-whereami (point)))))) 271 | 272 | (defun pry-search-for-source () 273 | (save-excursion 274 | (goto-char pry-last-prompt) 275 | (when (search-forward-regexp pry-source-location-regexp nil t) 276 | (pry-select-file 277 | (match-string-no-properties 1) 278 | (let ((line (string-to-number (match-string-no-properties 2)))) 279 | (if (search-forward-regexp "^ => +\\([0-a]+\\):" nil t) 280 | (string-to-number (match-string-no-properties 1)) 281 | line)))) 282 | 283 | (when (search-forward-regexp term-prompt-regexp nil t) 284 | (move-marker pry-last-prompt (point))))) 285 | 286 | 287 | (defun pry-send-raw () 288 | "Runs `term-send-raw' but first tries to align process-mark to point" 289 | (interactive) 290 | (pry-align-process-mark) 291 | (term-send-raw)) 292 | 293 | (defun pry-align-process-mark () 294 | "Move the Pry process cursor left or right to align with point" 295 | (let* ((pt (marker-position (process-mark (get-buffer-process (current-buffer))))) 296 | (readline-pos (save-excursion 297 | (goto-char (point-max)) 298 | (forward-line (if (looking-back "^$" (- (point-max) 2)) -1 0)) 299 | 300 | (when (looking-at term-prompt-regexp) 301 | (goto-char (match-end 0))) 302 | (if (>= pt (point)) 303 | (point) 304 | nil)))) 305 | (unless (or (eq pt (point)) (not readline-pos) (< (point) readline-pos)) 306 | (if (< pt (point)) 307 | (term-send-raw-string (format "\e%d\eOC" (- (point) pt))) 308 | (term-send-raw-string (format "\e%d\eOD" (- pt (point)))))))) 309 | 310 | (defun pry-send-right () (interactive) (pry-align-process-mark) (term-send-right)) 311 | (defun pry-send-left () (interactive) (pry-align-process-mark) (term-send-left)) 312 | (defun pry-send-del () (interactive) (pry-align-process-mark) (term-send-del)) 313 | (defun pry-send-backspace () (interactive) (pry-align-process-mark) (term-send-backspace)) 314 | (defun pry-send-raw-meta () (interactive) (pry-align-process-mark) (term-send-raw-meta)) 315 | 316 | 317 | (defun pry-mode () 318 | "Major mode for interacting with an inferior ruby (pry) process. 319 | 320 | \\{pry-raw-map}" 321 | (interactive) 322 | (term-mode) 323 | (setq term-scroll-show-maximum-output nil) 324 | (setq term-scroll-to-bottom-on-output t) 325 | (setq major-mode 'pry-mode) 326 | (setq mode-name "Pry") 327 | (make-local-variable 'term-raw-map) 328 | (move-marker pry-last-prompt (point-min)) 329 | (setq term-raw-map pry-raw-map) 330 | ;; (make-local-variable 'pry-cursor-overlay) 331 | ;; (when pry-cursor-overlay (delete-overlay pry-cursor-overlay)) 332 | ;; (setq pry-cursor-overlay (make-overlay (point-max) (point-max) nil t nil)) 333 | ;; (overlay-put pry-cursor-overlay 'face 'vcursor) 334 | (set (make-local-variable 'term-prompt-regexp) "^\\[[0-9]+\\] pry(.*)[>*] ")) 335 | 336 | 337 | (defvar pry-source-dir nil "Private variable.") 338 | 339 | (defun pry-source-dir () 340 | (or pry-source-dir 341 | (setq pry-source-dir (file-name-directory (find-lisp-object-file-name 342 | 'pry-source-dir (symbol-function 'pry-source-dir)))))) 343 | 344 | 345 | (defun pry-intercept (arg &optional break-type) 346 | "Run ruby program intercepting using pry on the current line. 347 | 348 | With no prefix argument, use value from last run. 349 | With prefix argument of: 350 | 0, edit command using previous command as default 351 | ^U, edit command using current buffer as default 352 | string, Run pry-intercept with value of string 353 | 354 | The optional argument BREAK-TYPE will set the pry breakpoint. for: 355 | nil, use the current buffer and line 356 | 'rerun, use the buffer and line of the `pry-intercept' 357 | 'nonstop, don't set a breakpoint 358 | 359 | See `pry-intercept-nonstop' and `pry-intercept-rerun'" 360 | (interactive "P") 361 | (let ((command 362 | (if (or (and arg (not (stringp arg))) (not (or arg pry-intercept-command))) 363 | (read-string "Run Pry: " (if (and pry-intercept-command (eq 0 arg)) 364 | pry-intercept-command 365 | (concat "ruby -I. " (buffer-file-name)))) 366 | (if (stringp arg) arg)))) 367 | 368 | (if command 369 | (setq pry-intercept-command command) 370 | (setq command pry-intercept-command)) 371 | 372 | (let* ((proc-buffer (get-buffer "*pry*")) 373 | (proc (get-buffer-process proc-buffer)) 374 | (process-environment process-environment) 375 | (main-prog-start (and (or (string-match " -- \\([^ ]+\\.rb\\)" command) (string-match " \\([^- ][^ ]*\\.rb\\)" command)) (match-beginning 1))) 376 | (pid (number-to-string (emacs-pid))) 377 | (fn (concat "/tmp/emacs_pry_" pid ".rb")) 378 | source) 379 | 380 | (unless (eq break-type 'rerun) 381 | (if (and (> (length buffer-file-name) 3) (string= (substring (buffer-file-name) -3) ".rb")) 382 | (if pry-target-mark 383 | (move-marker pry-target-mark (line-beginning-position) (current-buffer)) 384 | (setq pry-target-mark (copy-marker (line-beginning-position)))) 385 | (error "pry-intercept can only be run on ruby buffers"))) 386 | 387 | (with-current-buffer (marker-buffer pry-target-mark) 388 | (unless (eq break-type 'nonstop) 389 | (setq source (concat (buffer-substring 1 (marker-position pry-target-mark)) "binding.pry;" (buffer-substring (marker-position pry-target-mark) (1+ (buffer-size))))) 390 | 391 | (write-region source nil fn) 392 | 393 | (unless main-prog-start 394 | (error "Can't find ruby program name: %s" command)) 395 | 396 | (setenv "_EMACS_MONKEY_PATCH" (concat pid ":" (buffer-file-name)))) 397 | 398 | 399 | (setq command (concat (substring command 0 main-prog-start) (pry-source-dir) "ruby/emacs_pry.rb " (substring command main-prog-start)))) 400 | 401 | 402 | (when (and proc (equal (process-status proc) 'run)) 403 | (set-process-sentinel proc nil) 404 | (kill-process proc) 405 | (accept-process-output proc 0.5)) 406 | (when proc-buffer 407 | (with-current-buffer proc-buffer 408 | (setq buffer-undo-list t) 409 | (erase-buffer) 410 | (setq buffer-undo-list nil))) 411 | 412 | (run-pry command)))) 413 | 414 | (defun pry-intercept-nonstop (arg &optional break-type) 415 | "Same as `pry-intercept' but don't set pry breakpoint by default" 416 | (interactive "P") 417 | (pry-intercept arg (or break-type 'nonstop))) 418 | 419 | (defun pry-intercept-rerun (arg &optional break-type) 420 | "Same as `pry-intercept' but rerun last intercept by default" 421 | (interactive "P") 422 | (pry-intercept arg (or break-type 'rerun))) 423 | 424 | (provide 'pry) 425 | -------------------------------------------------------------------------------- /ruby/emacs_pry.rb: -------------------------------------------------------------------------------- 1 | begin 2 | require 'termios' 3 | rescue LoadError 4 | end 5 | require 'pry' 6 | require 'pry-nav' rescue nil 7 | 8 | # # FIXME 9 | # module Kernel 10 | # def fixme(*args) 11 | # STDOUT.puts args.inspect 12 | # STDOUT.flush 13 | # end 14 | # end 15 | 16 | def self._emacs_setup(main) 17 | class <(sym) do 38 | off=sym[0]=="-" 39 | sym=sym[1..-1] if off 40 | sym=sym.upcase.to_sym 41 | imode=flag_map[sym] 42 | if imode 43 | bit=::Termios.const_get(sym) 44 | cval=attrs.send(imode) 45 | if off 46 | cval &= ~bit 47 | else 48 | cval |= bit 49 | end 50 | attrs.send("#{imode}=",cval) 51 | end 52 | end 53 | 54 | # raw 55 | # %w[-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -opost -isig -icanon -xcase].each do |sym| 56 | # proc.call(sym) 57 | # end 58 | 59 | # STDIN.tcsetattr(::Termios::TCSANOW, attrs) 60 | 61 | 62 | # Pry.config.should_load_rc = false 63 | 64 | # require "awesome_print" 65 | 66 | # Pry.print = proc { |output, value| output.puts value.ai } 67 | 68 | 69 | # sane 70 | %w[cread -ignbrk brkint -inlcr -igncr icrnl -iutf8 -ixoff -iuclc -ixany imaxbel opost -olcuc -ocrnl onlcr 71 | -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh 72 | -xcase -tostop -echoprt echoctl echoke].each do |sym| 73 | proc.call(sym) 74 | end 75 | 76 | STDIN.tcsetattr(::Termios::TCSANOW, attrs) 77 | else 78 | system('stty sane') 79 | end 80 | 81 | Pry.config.color = true 82 | 83 | $_emacs_pid, $_emacs_monkey_patch=(ENV['_EMACS_MONKEY_PATCH']||'').split(':') 84 | if $_emacs_pid 85 | fn="/tmp/emacs_pry_#{$_emacs_pid}.rb" 86 | $_emacs_monkey_patch=File.expand_path($_emacs_monkey_patch) 87 | 88 | File.open(fn,"r") {|io| $_emacs_monkey_patch_source=io.read} 89 | File.unlink(fn) 90 | 91 | $0= ARGV.shift 92 | 93 | require_relative 'monkey_patch_require' 94 | if File.expand_path($0) == File.expand_path($_emacs_monkey_patch) 95 | $0=$_emacs_monkey_patch_source 96 | eval($_emacs_monkey_patch_source,main,$_emacs_monkey_patch) 97 | else 98 | load(File.expand_path($0)) 99 | ::Kernel.class_exec { 100 | alias require emacs_monkey_patch_original_require 101 | undef emacs_monkey_patch_original_require 102 | alias require_relative emacs_monkey_patch_original_require_relative 103 | undef emacs_monkey_patch_original_require_relative 104 | } 105 | end 106 | end 107 | end 108 | 109 | self._emacs_setup(binding) 110 | -------------------------------------------------------------------------------- /ruby/monkey_patch_require.rb: -------------------------------------------------------------------------------- 1 | class <<$_emacs_monkey_patch 2 | def check(path) 3 | if @basename == File.basename(path,".rb") 4 | path="#{path}#{@extname}" if File.extname(path).empty? 5 | if $:.find { |dir| File.expand_path(path,dir) == self } 6 | ::Kernel.class_exec { 7 | alias require emacs_monkey_patch_original_require 8 | undef emacs_monkey_patch_original_require 9 | } 10 | 11 | eval($_emacs_monkey_patch_source,@main,self) 12 | alias require_relative emacs_monkey_patch_original_require_relative 13 | undef emacs_monkey_patch_original_require_relative 14 | end 15 | end 16 | end 17 | 18 | def _init(main) 19 | @main=main 20 | @basename=File.basename(self,".rb") 21 | @extname=File.extname(self) 22 | $" << self 23 | end 24 | private :_init 25 | end 26 | $_emacs_monkey_patch.send(:_init,binding) 27 | 28 | module ::Kernel 29 | alias emacs_monkey_patch_original_require require 30 | alias emacs_monkey_patch_original_require_relative require_relative 31 | 32 | def require path 33 | emacs_monkey_patch_original_require(path) || $_emacs_monkey_patch.check(path) 34 | end 35 | 36 | def require_relative path 37 | require File.expand_path(path,File.dirname(caller.first.split(':').first)) 38 | end 39 | 40 | private :require, :emacs_monkey_patch_original_require 41 | end 42 | --------------------------------------------------------------------------------