public
Created

  • Download Gist
fix-162.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
Subject: [PATCH] Refactor macros for proper byte compilation. (ensime issue #162)
 
diff --git a/src/main/elisp/ensime-config.el b/src/main/elisp/ensime-config.el
index 52dca88..54af9d3 100644
--- a/src/main/elisp/ensime-config.el
+++ b/src/main/elisp/ensime-config.el
@@ -20,6 +20,7 @@
;; MA 02111-1307, USA.
+(eval-and-compile (require 'ensime-macros))
(defvar ensime-config-file-name ".ensime"
"The default file name for ensime project configurations.")
diff --git a/src/main/elisp/ensime-debug.el b/src/main/elisp/ensime-debug.el
index 304b05f..85863c8 100644
--- a/src/main/elisp/ensime-debug.el
+++ b/src/main/elisp/ensime-debug.el
@@ -22,6 +22,8 @@
(eval-and-compile
(require 'cl))
+(eval-and-compile (require 'ensime-macros))
+
(defgroup ensime-db nil
"Customization of ensime debugger support."
:group 'ensime
diff --git a/src/main/elisp/ensime-macros.el b/src/main/elisp/ensime-macros.el
new file mode 100644
index 0000000..9a29cda
--- /dev/null
+++ b/src/main/elisp/ensime-macros.el
@@ -0,0 +1,64 @@
+;;; ensime-macros.el
+;;
+;;;; License
+;;
+;; Copyright (C) 2010 Aemon Cannon
+;;
+;; This program is free software; you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 2 of
+;; the License, or (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public
+;; License along with this program; if not, write to the Free
+;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+;; MA 02111-1307, USA.
+
+(eval-when-compile (require 'cl))
+
+(defmacro ensime-with-conn-interactive (conn-sym &rest body)
+ "Surround body forms with a check to see if we're connected.
+If not, message the user."
+ `(let* ((,conn-sym (or (ensime-current-connection)
+ (ensime-prompt-for-connection))))
+ (if conn
+ (progn ,@body)
+ (message
+ "This command requires a connection to an ENSIME server."))))
+
+(defmacro* when-let ((var value) &rest body)
+ "Evaluate VALUE, if the result is non-nil bind it to VAR and eval BODY.
+
+\(fn (VAR VALUE) &rest BODY)"
+ `(let ((,var ,value))
+ (when ,var ,@body)))
+
+(defmacro* ensime-with-popup-buffer ((name &optional connection select)
+ &body body)
+ "Similar to `with-output-to-temp-buffer'.
+Bind standard-output and initialize some buffer-local variables.
+Restore window configuration when closed.
+
+NAME is the name of the buffer to be created.
+CONNECTION is the value for `ensime-buffer-connection'.
+If nil, no explicit connection is associated with
+the buffer. If t, the current connection is taken.
+"
+ `(let* ((vars% (list ,(if (eq connection t) '(ensime-connection) connection)))
+ (standard-output (ensime-make-popup-buffer ,name vars%)))
+ (with-current-buffer standard-output
+ (prog1
+ (progn
+ ,@body)
+ (assert (eq (current-buffer) standard-output))
+ (setq buffer-read-only t)
+ (set-window-point (ensime-display-popup-buffer ,(or select 'nil))
+ (point))))))
+
+
+(provide 'ensime-macros)
diff --git a/src/main/elisp/ensime-refactor.el b/src/main/elisp/ensime-refactor.el
index 4e31567..e0752d8 100644
--- a/src/main/elisp/ensime-refactor.el
+++ b/src/main/elisp/ensime-refactor.el
@@ -20,6 +20,8 @@
;; MA 02111-1307, USA.
+(eval-when-compile (require 'ensime-macros))
+
(defvar ensime-refactor-id-counter 0
"Each refactoring is given a unique id.")
@@ -211,4 +213,4 @@
-(provide 'ensime-refactor)
\ No newline at end of file
+(provide 'ensime-refactor)
diff --git a/src/main/elisp/ensime-search.el b/src/main/elisp/ensime-search.el
index ed97562..65a34b8 100644
--- a/src/main/elisp/ensime-search.el
+++ b/src/main/elisp/ensime-search.el
@@ -19,7 +19,9 @@
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
;; MA 02111-1307, USA.
-(eval-when-compile (require 'cl))
+(eval-when-compile
+ (require 'cl)
+ (require 'ensime-macros))
(defvar ensime-search-mode nil
diff --git a/src/main/elisp/ensime-test.el b/src/main/elisp/ensime-test.el
index e704964..0af6901 100644
--- a/src/main/elisp/ensime-test.el
+++ b/src/main/elisp/ensime-test.el
@@ -20,6 +20,8 @@
;; MA 02111-1307, USA.
+(eval-and-compile (require 'ensime))
+
(defvar ensime-testing-buffer "*ensime-tests*"
"Contains the output of all the tests. Also tracks all the testing-specific
buffer-local variables.")
@@ -1491,4 +1493,4 @@
-(provide 'ensime-test)
\ No newline at end of file
+(provide 'ensime-test)
diff --git a/src/main/elisp/ensime-undo.el b/src/main/elisp/ensime-undo.el
index 7ea938a..4358714 100644
--- a/src/main/elisp/ensime-undo.el
+++ b/src/main/elisp/ensime-undo.el
@@ -19,6 +19,7 @@
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
;; MA 02111-1307, USA.
+(eval-and-compile (require 'ensime-macros))
(defvar ensime-undo-info-buffer-name "*ENSIME-Undo*")
@@ -85,4 +86,4 @@
-(provide 'ensime-undo)
\ No newline at end of file
+(provide 'ensime-undo)
diff --git a/src/main/elisp/ensime.el b/src/main/elisp/ensime.el
index 3a33ff4..e962f33 100644
--- a/src/main/elisp/ensime.el
+++ b/src/main/elisp/ensime.el
@@ -33,8 +33,9 @@
(when (<= emacs-major-version 21)
(error "Ensime requires an Emacs version of 21, or above")))
-(eval-and-compile
- (require 'cl))
+(eval-when-compile
+ (require 'cl)
+ (require 'ensime-macros))
(require 'thingatpt)
(require 'comint)
@@ -150,6 +151,66 @@
"Single character offset to convert between emacs and
0-based character indexing.")
+;;; macros
+
+(defmacro ensime-assert-connected (&rest body)
+ "Surround body forms with a check to see if we're connected.
+If not, message the user."
+ `(if (ensime-connected-p)
+ (progn ,@body)
+ (message "This command requires a connection to an ENSIME server.")))
+
+(defmacro ensime-assert-buffer-saved-interactive (&rest body)
+ "Offer to save buffer if buffer is modified. Execute body only if
+buffer is saved."
+ `(if (buffer-modified-p)
+ (if (y-or-n-p "Buffer must be saved to continue. Save now? ")
+ (progn
+ (ensime-save-buffer-no-hooks)
+ ,@body))
+ (progn
+ ,@body)))
+
+(defmacro* ensime-with-connection-buffer ((&optional process) &rest body)
+ "Execute BODY in the process-buffer of PROCESS.
+If PROCESS is not specified, `ensime-connection' is used.
+
+\(fn (&optional PROCESS) &body BODY))"
+ `(with-current-buffer
+ (process-buffer (or ,process (ensime-connection)
+ (error "No connection")))
+ ,@body))
+
+(defmacro* ensime-with-inspector-buffer ((name object &optional select)
+ &body body)
+ "Extend the standard popup buffer with inspector-specific bindings."
+ `(ensime-with-popup-buffer
+ (,name t ,select)
+ (use-local-map ensime-popup-inspector-map)
+ (when (not ensime-inspector-paging-in-progress)
+
+ ;; Clamp the history cursor
+ (setq ensime-inspector-history-cursor
+ (max 0 ensime-inspector-history-cursor))
+ (setq ensime-inspector-history-cursor
+ (min (- (length ensime-inspector-history) 1)
+ ensime-inspector-history-cursor))
+
+ ;; Remove all elements preceding the cursor (the 'redo' history)
+ (setq ensime-inspector-history
+ (subseq ensime-inspector-history
+ ensime-inspector-history-cursor))
+
+ ;; Add the new history item
+ (push ,object ensime-inspector-history)
+
+ ;; Set cursor to point to the new item
+ (setq ensime-inspector-history-cursor 0)
+
+ )
+ ,@body
+ ))
+
;;;;; ensime-mode
(defgroup ensime-mode nil
@@ -615,7 +676,6 @@ Do not show 'Writing..' message."
(ensime-inferior-connect config server-proc)))
)))
-
(defun ensime-reload ()
"Re-initialize the project with the current state of the config file.
Analyzer will be restarted. All source will be recompiled."
@@ -733,23 +793,6 @@ defined."
(let ((config (ensime-config (ensime-current-connection))))
(plist-get config :root-dir))))
-(defmacro ensime-assert-connected (&rest body)
- "Surround body forms with a check to see if we're connected.
-If not, message the user."
- `(if (ensime-connected-p)
- (progn ,@body)
- (message "This command requires a connection to an ENSIME server.")))
-
-(defmacro ensime-with-conn-interactive (conn-sym &rest body)
- "Surround body forms with a check to see if we're connected.
-If not, message the user."
- `(let* ((,conn-sym (or (ensime-current-connection)
- (ensime-prompt-for-connection))))
- (if conn
- (progn ,@body)
- (message
- "This command requires a connection to an ENSIME server."))))
-
(defun ensime-swank-port-file ()
"Filename where the SWANK server writes its TCP port number."
(ensime-temp-file-name (format "ensime_port.%S" (emacs-pid))))
@@ -1072,17 +1115,6 @@ The default condition handler for timer functions (see
(defun ensime-strip-dollar-signs (str)
(replace-regexp-in-string "\\$" "" str))
-(defmacro ensime-assert-buffer-saved-interactive (&rest body)
- "Offer to save buffer if buffer is modified. Execute body only if
-buffer is saved."
- `(if (buffer-modified-p)
- (if (y-or-n-p "Buffer must be saved to continue. Save now? ")
- (progn
- (ensime-save-buffer-no-hooks)
- ,@body))
- (progn
- ,@body)))
-
(defun ensime-assert-executable-on-path (name)
(when (null (executable-find name))
(error (concat name " not found on your emacs exec-path. "
@@ -1094,14 +1126,6 @@ buffer is saved."
str)
-(defmacro* when-let ((var value) &rest body)
- "Evaluate VALUE, if the result is non-nil bind it to VAR and eval BODY.
-
-\(fn (VAR VALUE) &rest BODY)"
- `(let ((,var ,value))
- (when ,var ,@body)))
-
-
(defmacro destructure-case (value &rest patterns)
"Dispatch VALUE to one of PATTERNS.
A cross between `case' and `destructuring-bind'.
@@ -1732,16 +1756,6 @@ This doesn't mean it will connect right after Ensime is loaded."
process))
-(defmacro* ensime-with-connection-buffer ((&optional process) &rest body)
- "Execute BODY in the process-buffer of PROCESS.
-If PROCESS is not specified, `ensime-connection' is used.
-
-\(fn (&optional PROCESS) &body BODY))"
- `(with-current-buffer
- (process-buffer (or ,process (ensime-connection)
- (error "No connection")))
- ,@body))
-
(defun ensime-connect (host port)
"Connect to a running Swank server. Return the connection."
(interactive (list
@@ -3750,37 +3764,6 @@ inspect the package of the current source file."
"Type and package inspector key bindings.")
-(defmacro* ensime-with-inspector-buffer ((name object &optional select)
- &body body)
- "Extend the standard popup buffer with inspector-specific bindings."
- `(ensime-with-popup-buffer
- (,name t ,select)
- (use-local-map ensime-popup-inspector-map)
- (when (not ensime-inspector-paging-in-progress)
-
- ;; Clamp the history cursor
- (setq ensime-inspector-history-cursor
- (max 0 ensime-inspector-history-cursor))
- (setq ensime-inspector-history-cursor
- (min (- (length ensime-inspector-history) 1)
- ensime-inspector-history-cursor))
-
- ;; Remove all elements preceding the cursor (the 'redo' history)
- (setq ensime-inspector-history
- (subseq ensime-inspector-history
- ensime-inspector-history-cursor))
-
- ;; Add the new history item
- (push ,object ensime-inspector-history)
-
- ;; Set cursor to point to the new item
- (setq ensime-inspector-history-cursor 0)
-
- )
- ,@body
- ))
-
-
;; Interface
(defvar ensime-message-function 'message)
@@ -4048,29 +4031,6 @@ See `view-return-to-alist' for a similar idea.")
"So we can query later whether this is a popup buffer."))
;; Interface
-(defmacro* ensime-with-popup-buffer ((name &optional connection select)
- &body body)
- "Similar to `with-output-to-temp-buffer'.
-Bind standard-output and initialize some buffer-local variables.
-Restore window configuration when closed.
-
-NAME is the name of the buffer to be created.
-CONNECTION is the value for `ensime-buffer-connection'.
-If nil, no explicit connection is associated with
-the buffer. If t, the current connection is taken.
-"
- `(let* ((vars% (list ,(if (eq connection t) '(ensime-connection) connection)))
- (standard-output (ensime-make-popup-buffer ,name vars%)))
- (with-current-buffer standard-output
- (prog1
- (progn
- ,@body)
- (assert (eq (current-buffer) standard-output))
- (setq buffer-read-only t)
- (set-window-point (ensime-display-popup-buffer ,(or select 'nil))
- (point))))))
-
-
(defun ensime-make-popup-buffer (name buffer-vars)
"Return a temporary buffer called NAME.
The buffer also uses the minor-mode `ensime-popup-buffer-mode'."

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.