diff options
| author | Leo Liu | 2013-12-08 15:18:46 +0800 |
|---|---|---|
| committer | Leo Liu | 2013-12-08 15:18:46 +0800 |
| commit | 6407822c66a86abe01eea33d7eca662e3e7c2b60 (patch) | |
| tree | 0ba05dd0eeaa3ef7830b5ff02c27f144e4a85543 | |
| parent | 6f8dfccfe3ec3e1137e712b49da12c8a9ab4bc85 (diff) | |
| download | emacs-6407822c66a86abe01eea33d7eca662e3e7c2b60.tar.gz emacs-6407822c66a86abe01eea33d7eca662e3e7c2b60.zip | |
Re-implement popup menu for flymake
* progmodes/flymake.el (flymake-popup-current-error-menu): Rename
from flymake-display-err-menu-for-current-line. Reimplement.
(flymake-posn-at-point-as-event, flymake-popup-menu)
(flymake-make-emacs-menu): Remove.
Fixes: debbugs:16077
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/progmodes/flymake.el | 118 |
2 files changed, 37 insertions, 88 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1e384f25579..1b4606a0d27 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2013-12-08 Leo Liu <sdl.web@gmail.com> | ||
| 2 | |||
| 3 | * progmodes/flymake.el (flymake-popup-current-error-menu): Rename | ||
| 4 | from flymake-display-err-menu-for-current-line. Reimplement. | ||
| 5 | (flymake-posn-at-point-as-event, flymake-popup-menu) | ||
| 6 | (flymake-make-emacs-menu): Remove. (Bug#16077) | ||
| 7 | |||
| 1 | 2013-12-08 Stefan Monnier <monnier@iro.umontreal.ca> | 8 | 2013-12-08 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 9 | ||
| 3 | * emulation/cua-rect.el (cua--rectangle-region-extract): New function. | 10 | * emulation/cua-rect.el (cua--rectangle-region-extract): New function. |
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el index 48ff486a9e5..b5e33ff2574 100644 --- a/lisp/progmodes/flymake.el +++ b/lisp/progmodes/flymake.el | |||
| @@ -192,55 +192,6 @@ NAME is the file name function to use, default `flymake-get-real-file-name'." | |||
| 192 | (defvar-local flymake-new-err-info nil | 192 | (defvar-local flymake-new-err-info nil |
| 193 | "Same as `flymake-err-info', effective when a syntax check is in progress.") | 193 | "Same as `flymake-err-info', effective when a syntax check is in progress.") |
| 194 | 194 | ||
| 195 | (defun flymake-posn-at-point-as-event (&optional position window dx dy) | ||
| 196 | "Return pixel position of top left corner of glyph at POSITION. | ||
| 197 | |||
| 198 | The position is relative to top left corner of WINDOW, as a | ||
| 199 | mouse-1 click event (identical to the event that would be | ||
| 200 | triggered by clicking mouse button 1 at the top left corner of | ||
| 201 | the glyph). | ||
| 202 | |||
| 203 | POSITION and WINDOW default to the position of point in the | ||
| 204 | selected window. | ||
| 205 | |||
| 206 | DX and DY specify optional offsets from the top left of the glyph." | ||
| 207 | (let* ((window (or window (selected-window))) | ||
| 208 | (position (or position (window-point window))) | ||
| 209 | (dx (or dx 0)) | ||
| 210 | (dy (or dy 0)) | ||
| 211 | (pos (posn-at-point position window)) | ||
| 212 | (x-y (posn-x-y pos)) | ||
| 213 | (edges (window-inside-pixel-edges window)) | ||
| 214 | (win-x-y (window-pixel-edges window))) | ||
| 215 | ;; adjust for window edges | ||
| 216 | (setcar (nthcdr 2 pos) | ||
| 217 | (cons (+ (car x-y) (car edges) (- (car win-x-y)) dx) | ||
| 218 | (+ (cdr x-y) (cadr edges) (- (cadr win-x-y)) dy))) | ||
| 219 | (list 'mouse-1 pos))) | ||
| 220 | |||
| 221 | ;;; XXX: get rid of the following two functions | ||
| 222 | |||
| 223 | (defun flymake-popup-menu (menu-data) | ||
| 224 | "Pop up the flymake menu at point, using the data MENU-DATA. | ||
| 225 | POS is a list of the form ((X Y) WINDOW), where X and Y are | ||
| 226 | pixels positions from the top left corner of WINDOW's frame. | ||
| 227 | MENU-DATA is a list of error and warning messages returned by | ||
| 228 | `flymake-make-err-menu-data'." | ||
| 229 | (x-popup-menu (flymake-posn-at-point-as-event) | ||
| 230 | (flymake-make-emacs-menu menu-data))) | ||
| 231 | |||
| 232 | (defun flymake-make-emacs-menu (menu-data) | ||
| 233 | "Return a menu specifier using MENU-DATA. | ||
| 234 | MENU-DATA is a list of error and warning messages returned by | ||
| 235 | `flymake-make-err-menu-data'. | ||
| 236 | See `x-popup-menu' for the menu specifier format." | ||
| 237 | (let* ((menu-title (nth 0 menu-data)) | ||
| 238 | (menu-items (nth 1 menu-data)) | ||
| 239 | (menu-commands (mapcar (lambda (foo) | ||
| 240 | (cons (nth 0 foo) (nth 1 foo))) | ||
| 241 | menu-items))) | ||
| 242 | (list menu-title (cons "" menu-commands)))) | ||
| 243 | |||
| 244 | (defun flymake-log (level text &rest args) | 195 | (defun flymake-log (level text &rest args) |
| 245 | "Log a message at level LEVEL. | 196 | "Log a message at level LEVEL. |
| 246 | If LEVEL is higher than `flymake-log-level', the message is | 197 | If LEVEL is higher than `flymake-log-level', the message is |
| @@ -1223,45 +1174,36 @@ For the format of LINE-ERR-INFO, see `flymake-ler-make-ler'." | |||
| 1223 | (flymake-log 3 "starting syntax check as more than 1 second passed since last change") | 1174 | (flymake-log 3 "starting syntax check as more than 1 second passed since last change") |
| 1224 | (flymake-start-syntax-check))))) | 1175 | (flymake-start-syntax-check))))) |
| 1225 | 1176 | ||
| 1226 | (defun flymake-display-err-menu-for-current-line () | 1177 | (define-obsolete-function-alias 'flymake-display-err-menu-for-current-line |
| 1227 | "Display a menu with errors/warnings for current line if it has errors and/or warnings." | 1178 | 'flymake-popup-current-error-menu "24.4") |
| 1228 | (interactive) | 1179 | |
| 1229 | (let* ((line-no (line-number-at-pos)) | 1180 | (defun flymake-popup-current-error-menu (&optional event) |
| 1230 | (line-err-info-list (nth 0 (flymake-find-err-info flymake-err-info line-no))) | 1181 | "Pop up a menu with errors/warnings for current line." |
| 1231 | (menu-data (flymake-make-err-menu-data line-no line-err-info-list)) | 1182 | (interactive (list last-nonmenu-event)) |
| 1232 | (choice nil)) | 1183 | (let* ((line-no (line-number-at-pos)) |
| 1233 | (if menu-data | 1184 | (errors (or (car (flymake-find-err-info flymake-err-info line-no)) |
| 1234 | (progn | 1185 | (user-error "No errors for current line"))) |
| 1235 | (setq choice (flymake-popup-menu menu-data)) | 1186 | (menu (mapcar (lambda (x) |
| 1236 | (flymake-log 3 "choice=%s" choice) | 1187 | (if (flymake-ler-file x) |
| 1237 | (when choice | 1188 | (cons (format "%s - %s(%d)" |
| 1238 | (eval choice))) | 1189 | (flymake-ler-text x) |
| 1239 | (flymake-log 1 "no errors for line %d" line-no)))) | 1190 | (flymake-ler-file x) |
| 1240 | 1191 | (flymake-ler-line x)) | |
| 1241 | (defun flymake-make-err-menu-data (line-no line-err-info-list) | 1192 | x) |
| 1242 | "Make a (menu-title (item-title item-action)*) list with errors/warnings from LINE-ERR-INFO-LIST." | 1193 | (list (flymake-ler-text x)))) |
| 1243 | (let* ((menu-items nil)) | 1194 | errors)) |
| 1244 | (when line-err-info-list | 1195 | (event (if (mouse-event-p event) |
| 1245 | (let* ((count (length line-err-info-list)) | 1196 | event |
| 1246 | (menu-item-text nil)) | 1197 | (list 'mouse-1 (posn-at-point)))) |
| 1247 | (while (> count 0) | 1198 | (title (format "Line %d: %d error(s), %d warning(s)" |
| 1248 | (setq menu-item-text (flymake-ler-text (nth (1- count) line-err-info-list))) | 1199 | line-no |
| 1249 | (let* ((file (flymake-ler-file (nth (1- count) line-err-info-list))) | 1200 | (flymake-get-line-err-count errors "e") |
| 1250 | (full-file (flymake-ler-full-file (nth (1- count) line-err-info-list))) | 1201 | (flymake-get-line-err-count errors "w"))) |
| 1251 | (line (flymake-ler-line (nth (1- count) line-err-info-list)))) | 1202 | (choice (x-popup-menu event (list title (cons "" menu))))) |
| 1252 | (if file | 1203 | (flymake-log 3 "choice=%s" choice) |
| 1253 | (setq menu-item-text (concat menu-item-text " - " file "(" (format "%d" line) ")"))) | 1204 | (when choice |
| 1254 | (setq menu-items (cons (list menu-item-text | 1205 | (flymake-goto-file-and-line (flymake-ler-full-file choice) |
| 1255 | (if file (list 'flymake-goto-file-and-line full-file line) nil)) | 1206 | (flymake-ler-line choice))))) |
| 1256 | menu-items))) | ||
| 1257 | (setq count (1- count))) | ||
| 1258 | (flymake-log 3 "created menu-items with %d item(s)" (length menu-items)))) | ||
| 1259 | (if menu-items | ||
| 1260 | (let* ((menu-title (format "Line %d: %d error(s), %d warning(s)" line-no | ||
| 1261 | (flymake-get-line-err-count line-err-info-list "e") | ||
| 1262 | (flymake-get-line-err-count line-err-info-list "w")))) | ||
| 1263 | (list menu-title menu-items)) | ||
| 1264 | nil))) | ||
| 1265 | 1207 | ||
| 1266 | (defun flymake-goto-file-and-line (file line) | 1208 | (defun flymake-goto-file-and-line (file line) |
| 1267 | "Try to get buffer for FILE and goto line LINE in it." | 1209 | "Try to get buffer for FILE and goto line LINE in it." |