├── .gitignore ├── Cask ├── README.rst └── sourcetrail.el /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled 2 | *.elc 3 | 4 | # Packaging 5 | .cask 6 | -------------------------------------------------------------------------------- /Cask: -------------------------------------------------------------------------------- 1 | (source gnu) 2 | (source melpa) 3 | 4 | (package-file "sourcetrail.el") 5 | 6 | (development 7 | (depends-on "f") 8 | (depends-on "ecukes") 9 | (depends-on "ert-runner") 10 | (depends-on "el-mock")) 11 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | emacs-sourcetrail 2 | =========== 3 | 4 | emacs-sourcetrail is a plugin for Emacs to communicate with Sourcetrail_. 5 | 6 | .. _Sourcetrail: https://sourcetrail.io 7 | 8 | Install 9 | ------- 10 | 11 | Usage 12 | ----- 13 | 14 | From Sourcetrail to Emacs 15 | ~~~~~~~~~~~~~~~~~~~ 16 | 17 | * enable sourcetrail-mode in Emacs 18 | * Right click in sourcetrail -> **Set IDE Curor** 19 | * In the Emacs should now open the file and put the cursor in the position form sourcetrail. 20 | 21 | From Emacs to Sourcetrail 22 | ~~~~~~~~~~~~~~~~~~~ 23 | 24 | * Navigate your cursor to the location in the text. 25 | * Sent location to sourcetrail 26 | 27 | + Press **M-x** and enter **sourcetrail-send-loation** 28 | + bind **sourcetrail-send-location** to a key sequence and use it. 29 | 30 | Preferences 31 | ----------- 32 | 33 | * **M-x** customize 34 | * search for sourcetrail 35 | * 3 Settings should be displayed now 36 | 37 | Emacs Sourcetrail Ip 38 | ~~~~~~~~~~~~~~ 39 | 40 | Ip address for the Tcp communcation, default is ``localhost`` 41 | 42 | Emacs Sourcetrail Port Sourcetrail 43 | ~~~~~~~~~~~~~~~~~~~~~~ 44 | 45 | Port Sourcetrail listens to, default is ``6667`` 46 | 47 | Emacs Sourcetrail Port Emacs 48 | ~~~~~~~~~~~~~~~~~~~~~~ 49 | 50 | Port Sourcetrail listens to, default is ``6666`` 51 | 52 | -------------------------------------------------------------------------------- /sourcetrail.el: -------------------------------------------------------------------------------- 1 | ;;; sourcetrail.el --- Communication with Sourcetrail -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2016 4 | 5 | ;; Author: Andreas Stallinger 6 | ;; Keywords: external, tool 7 | ;; Version: 0.1 8 | ;; Package-Requires: ((emacs "24.4")) 9 | 10 | ;; License: 11 | 12 | ;; This file is not part of GNU Emacs 13 | 14 | ;; The MIT License (MIT) 15 | ;; Copyright (c) 2016 Coati Software OG 16 | 17 | ;; Permission is hereby granted, free of charge, to any person obtaining 18 | ;; a copy of this software and associated documentation files (the "Software"), 19 | ;; to deal in the Software without restriction, including without limitation 20 | ;; the rights to use, copy, modify, merge, publish, distribute, sublicense, 21 | ;; and/or sell copies of the Software, and to permit persons to whom the 22 | ;; Software is furnished to do so, subject to the following conditions: 23 | 24 | ;; The above copyright notice and this permission notice shall be 25 | ;; included in all copies or substantial portions of the Software. 26 | 27 | ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 28 | ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 29 | ;; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 30 | ;; IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 31 | ;; DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 32 | ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 33 | ;; OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 34 | 35 | 36 | ;;; Commentary: 37 | 38 | ;;emacs-sourcetrail 39 | ;;=========== 40 | 41 | ;;emacs-sourcetrail is a plugin for Emacs to communicate with Sourcetrail_. 42 | 43 | ;;.. _Sourcetrail: https://sourcetrail.com 44 | 45 | ;;Install 46 | ;;------- 47 | 48 | ;;Usage 49 | ;;----- 50 | 51 | ;;From Sourcetrail to Emacs 52 | ;;~~~~~~~~~~~~~~~~~~~ 53 | 54 | ;;* enable sourcetrail-mode in Emacs 55 | ;;* Right click in sourcetrail -> **Set IDE Curor** 56 | ;;* In the Emacs should now open the file and put the cursor in the position form sourcetrail. 57 | 58 | ;;From Emacs to Sourcetrail 59 | ;;~~~~~~~~~~~~~~~~~~~ 60 | 61 | ;;* Navigate your cursor to the location in the text. 62 | ;;* Sent location to sourcetrail 63 | 64 | ;; ;+ Press **M-x** and enter **sourcetrail-send-loation** 65 | ;; ;+ bind **sourcetrail-send-location** to a key sequence and use it. 66 | 67 | ;;Preferences 68 | ;;----------- 69 | 70 | ;;* **M-x** customize 71 | ;;* search for sourcetrail 72 | ;;* 3 Settins should be displayed now 73 | 74 | ;;Emacs Sourcetrail Ip 75 | ;;~~~~~~~~~~~~~~ 76 | 77 | ;;Ip address for the Tcp communcation, default is ``localhost`` 78 | 79 | ;;Emacs Sourcetrail Port Sourcetrail 80 | ;;~~~~~~~~~~~~~~~~~~~~~~ 81 | 82 | ;;Port Sourcetrail listens to, default is ``6667`` 83 | 84 | ;;Emacs Sourcetrail Port Emacs 85 | ;;~~~~~~~~~~~~~~~~~~~~~~ 86 | 87 | ;;Port Sourcetrail listens to, default is ``6666`` 88 | 89 | 90 | ;;; Code: 91 | (require 'subr-x) 92 | 93 | (defgroup sourcetrail nil 94 | "Settings for the sourcetrail plugin." 95 | :group 'external) 96 | 97 | (defcustom sourcetrail-port-sourcetrail 6667 98 | "Port Sourcetrail listens to." 99 | :group 'sourcetrail 100 | :type '(number)) 101 | 102 | (defcustom sourcetrail-port-emacs 6666 103 | "Port for listening to Sourcetrail." 104 | :group 'sourcetrail 105 | :type '(number)) 106 | 107 | (defcustom sourcetrail-ip "localhost" 108 | "Ip for communication with sourcetrail." 109 | :group 'sourcetrail 110 | :type '(string)) 111 | 112 | (defconst sourcetrail-server-name "sourcetrail-server") 113 | (defconst sourcetrail-server-buffer "*-sourcetrail-server-buffer*") 114 | (defvar sourcetrail-server nil) 115 | (defvar sourcetrail-client nil) 116 | (defvar sourcetrail-col nil) 117 | (defvar sourcetrail-row nil) 118 | (defvar sourcetrail-file nil) 119 | (defvar sourcetrail-message nil) 120 | 121 | (defun buildTokenLocationMessage nil 122 | "Building a formated message for sending to sourcetrail." 123 | (setq sourcetrail-col (number-to-string (current-column))) 124 | (setq sourcetrail-row (number-to-string (line-number-at-pos))) 125 | (setq sourcetrail-file (buffer-file-name)) 126 | (setq sourcetrail-message (mapconcat 'identity (list "setActiveToken" sourcetrail-file sourcetrail-row sourcetrail-col) ">>")) 127 | (setq sourcetrail-message (mapconcat 'identity (list sourcetrail-message "") ""))) 128 | 129 | (defun sourcetrail-send-ping nil 130 | "Sending ping to sourcetrail." 131 | (setq sourcetrail-client 132 | (open-network-stream "sourcetrail-client" 133 | "*sourcetrail-client*" sourcetrail-ip sourcetrail-port-sourcetrail)) 134 | (process-send-string sourcetrail-client "ping>>Emacs")) 135 | 136 | (defun sourcetrail-send-message(message) 137 | "Sending message to sourcetrail." 138 | (setq sourcetrail-client 139 | (open-network-stream "sourcetrail-client" 140 | "*sourcetrail-client*" sourcetrail-ip sourcetrail-port-sourcetrail)) 141 | (process-send-string sourcetrail-client message)) 142 | 143 | (defun sourcetrail-server-start nil 144 | "Start tcp server." 145 | (unless sourcetrail-server 146 | (setq sourcetrail-server 147 | (make-network-process :name (or sourcetrail-server-name "*sourcetrail-server") 148 | :server t 149 | :service (or sourcetrail-port-emacs 6666) 150 | :family 'ipv4 151 | :buffer sourcetrail-server-buffer 152 | :filter 'sourcetrail-listen-filter)) 153 | (if sourcetrail-server 154 | (set-process-query-on-exit-flag sourcetrail-server nil) 155 | (error "Could not start server process")) 156 | (sourcetrail-send-ping))) 157 | 158 | (defun sourcetrail-listen-filter (proc string) 159 | "Tcp listener filter. No need for PROC. STRING is the command send from sourcetrail." 160 | (process-buffer proc) 161 | (if (string-suffix-p "" string) 162 | (progn 163 | ;; split message 164 | (setq sourcetrail-message (split-string (string-remove-suffix "" string) ">>")) 165 | (when (string= (car sourcetrail-message) "moveCursor") 166 | ;;moveCuror message 167 | ;; filepath 168 | (setq sourcetrail-file (nth 1 sourcetrail-message)) 169 | ;; row and col 170 | (setq sourcetrail-row (string-to-number (nth 2 sourcetrail-message))) 171 | (setq sourcetrail-col (string-to-number (nth 3 sourcetrail-message))) 172 | ;; open file 173 | (find-file sourcetrail-file) 174 | ;; move cursor 175 | (forward-line (- sourcetrail-row (line-number-at-pos))) 176 | (move-to-column sourcetrail-col) 177 | ) 178 | (when (string= (car sourcetrail-message) "ping") 179 | (sourcetrail-send-ping) 180 | ) 181 | ) 182 | (message "Could not process the message from sourcetrail: %s" string) 183 | ) 184 | ) 185 | 186 | (defun sourcetrail-server-stop nil 187 | "Stops TCP Listener for Sourcetrail." 188 | (when sourcetrail-server 189 | (delete-process sourcetrail-server-name) 190 | (setq sourcetrail-server nil))) 191 | 192 | ;;;###autoload 193 | (defun sourcetrail-send-location nil 194 | "Sends current location to Sourcetrail." 195 | (interactive) 196 | (sourcetrail-send-message (buildTokenLocationMessage)) 197 | ) 198 | 199 | ;;;###autoload 200 | (define-minor-mode sourcetrail-mode 201 | "Start/stop sourcetrail mode." 202 | :global t 203 | :lighter " sourcetrail" 204 | ; value of sourcetrail-mode is toggled before this implicitly 205 | (if sourcetrail-mode (sourcetrail-server-start) (sourcetrail-server-stop))) 206 | 207 | (provide 'sourcetrail) 208 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 209 | ;;; sourcetrail.el ends here 210 | --------------------------------------------------------------------------------