*** trunk/lisp/progmodes/flymake.el 2013-02-03 09:46:50.383143000 +0800 --- trunk/lisp/progmodes/flymake.el.new 2013-02-23 21:49:13.333088549 +0800 *************** *** 1,4 **** ! ;;; flymake.el -- a universal on-the-fly syntax checker ;; Copyright (C) 2003-2013 Free Software Foundation, Inc. --- 1,4 ---- ! ;;; flymake.el --- a universal on-the-fly syntax checker ;; Copyright (C) 2003-2013 Free Software Foundation, Inc. *************** *** 26,32 **** ;; ;; Flymake is a minor Emacs mode performing on-the-fly syntax ;; checks using the external syntax check tool (for C/C++ this ! ;; is usually the compiler) ;;; Bugs/todo: --- 26,32 ---- ;; ;; Flymake is a minor Emacs mode performing on-the-fly syntax ;; checks using the external syntax check tool (for C/C++ this ! ;; is usually the compiler). ;;; Bugs/todo: *************** *** 66,73 **** "Same as `flymake-err-info', effective when a syntax check is in progress.") (make-variable-buffer-local 'flymake-new-err-info) ! ;;;; [[ cross-emacs compatibility routines (defsubst flymake-makehash (&optional test) (if (fboundp 'make-hash-table) (if test (make-hash-table :test test) (make-hash-table)) (with-no-warnings --- 66,76 ---- "Same as `flymake-err-info', effective when a syntax check is in progress.") (make-variable-buffer-local 'flymake-new-err-info) ! ;;;; [[ cross-emacsen compatibility routines (defsubst flymake-makehash (&optional test) + "Create and return a new hash table using TEST to compare keys. + It uses the function `make-hash-table' to make a hash-table if + you use GNU Emacs, otherwise it uses `makehash'." (if (fboundp 'make-hash-table) (if test (make-hash-table :test test) (make-hash-table)) (with-no-warnings *************** Zero-length substrings at the beginning *** 106,115 **** (lambda () temporary-file-directory))) (defun flymake-posn-at-point-as-event (&optional position window dx dy) ! "Return pixel position of top left corner of glyph at POSITION, ! relative to top left corner of WINDOW, as a mouse-1 click ! event (identical to the event that would be triggered by clicking ! mouse button 1 at the top left corner of the glyph). POSITION and WINDOW default to the position of point in the selected window. --- 109,120 ---- (lambda () temporary-file-directory))) (defun flymake-posn-at-point-as-event (&optional position window dx dy) ! "Return pixel position of top left corner of glyph at POSITION. ! ! The position is relative to top left corner of WINDOW, as a ! mouse-1 click event (identical to the event that would be ! triggered by clicking mouse button 1 at the top left corner of ! the glyph). POSITION and WINDOW default to the position of point in the selected window. *************** See `x-popup-menu' for the menu specifie *** 164,170 **** (if (featurep 'xemacs) (progn ! (defun flymake-nop ()) (defun flymake-make-xemacs-menu (menu-data) "Return a menu specifier using MENU-DATA." --- 169,176 ---- (if (featurep 'xemacs) (progn ! (defun flymake-nop () ! "Do nothing.") (defun flymake-make-xemacs-menu (menu-data) "Return a menu specifier using MENU-DATA." *************** See `x-popup-menu' for the menu specifie *** 187,192 **** --- 193,199 ---- (count-lines (window-start) (point)))) (defun flymake-selected-frame () + "Return the frame that is now selected." (if (fboundp 'window-edges) (selected-frame) (selected-window))) *************** See `x-popup-menu' for the menu specifie *** 217,247 **** :group 'flymake :type 'integer) (defun flymake-log (level text &rest args) "Log a message at level LEVEL. If LEVEL is higher than `flymake-log-level', the message is ignored. Otherwise, it is printed using `message'. TEXT is a format control string, and the remaining arguments ARGS ! are the string substitutions (see `format')." (if (<= level flymake-log-level) (let* ((msg (apply 'format text args))) (message "%s" msg) ;;(with-temp-buffer ;; (insert msg) ;; (insert "\n") ! ;; (flymake-save-buffer-in-file "d:/flymake.log" t) ; make log file name customizable ;;) ))) (defun flymake-ins-after (list pos val) ! "Insert VAL into LIST after position POS." ! (let ((tmp (copy-sequence list))) ; (???) (setcdr (nthcdr pos tmp) (cons val (nthcdr (1+ pos) tmp))) tmp)) (defun flymake-set-at (list pos val) ! "Set VAL at position POS in LIST." ! (let ((tmp (copy-sequence list))) ; (???) (setcar (nthcdr pos tmp) val) tmp)) --- 224,263 ---- :group 'flymake :type 'integer) + ;; (defcustom flymake-log-file-name "~/flymake.log" + ;; "Where to put the flymake log if logging is enabled. + + ;; See `flymake-log-level' if you want to control what is logged." + ;; :group 'flymake + ;; :type 'string) + (defun flymake-log (level text &rest args) "Log a message at level LEVEL. If LEVEL is higher than `flymake-log-level', the message is ignored. Otherwise, it is printed using `message'. TEXT is a format control string, and the remaining arguments ARGS ! are the string substitutions (see the function `format')." (if (<= level flymake-log-level) (let* ((msg (apply 'format text args))) (message "%s" msg) ;;(with-temp-buffer ;; (insert msg) ;; (insert "\n") ! ;; (flymake-save-buffer-in-file "~/flymake.log") ; make log file name customizable ;;) ))) (defun flymake-ins-after (list pos val) ! "Insert VAL into LIST after position POS. ! POS counts from zero." ! (let ((tmp (copy-sequence list))) ; Bind `tmp' to a copy of LIST (setcdr (nthcdr pos tmp) (cons val (nthcdr (1+ pos) tmp))) tmp)) (defun flymake-set-at (list pos val) ! "Set VAL at position POS in LIST. ! POS counts from zero." ! (let ((tmp (copy-sequence list))) ; Bind `tmp' to a copy of LIST (setcar (nthcdr pos tmp) val) tmp)) *************** are the string substitutions (see `forma *** 249,255 **** "List of currently active flymake processes.") (defvar flymake-output-residual nil) - (make-variable-buffer-local 'flymake-output-residual) (defgroup flymake nil --- 265,270 ---- *************** are the string substitutions (see `forma *** 284,294 **** :type '(repeat (string symbol symbol symbol))) (defun flymake-get-file-name-mode-and-masks (file-name) ! "Return the corresponding entry from `flymake-allowed-file-name-masks'." (unless (stringp file-name) (error "Invalid file-name")) (let ((fnm flymake-allowed-file-name-masks) ! (mode-and-masks nil)) (while (and (not mode-and-masks) fnm) (if (string-match (car (car fnm)) file-name) (setq mode-and-masks (cdr (car fnm)))) --- 299,309 ---- :type '(repeat (string symbol symbol symbol))) (defun flymake-get-file-name-mode-and-masks (file-name) ! "Return the function(s) correspond(s) to FILE-NAME in `flymake-allowed-file-name-masks'." (unless (stringp file-name) (error "Invalid file-name")) (let ((fnm flymake-allowed-file-name-masks) ! (mode-and-masks nil)) (while (and (not mode-and-masks) fnm) (if (string-match (car (car fnm)) file-name) (setq mode-and-masks (cdr (car fnm)))) *************** are the string substitutions (see `forma *** 296,335 **** (flymake-log 3 "file %s, init=%s" file-name (car mode-and-masks)) mode-and-masks)) - (defun flymake-can-syntax-check-file (file-name) - "Determine whether we can syntax check FILE-NAME. - Return nil if we cannot, non-nil if we can." - (if (flymake-get-init-function file-name) t nil)) - (defun flymake-get-init-function (file-name) ! "Return init function to be used for the file." (let* ((init-f (nth 0 (flymake-get-file-name-mode-and-masks file-name)))) ;;(flymake-log 0 "calling %s" init-f) ;;(funcall init-f (current-buffer)) init-f)) (defun flymake-get-cleanup-function (file-name) ! "Return cleanup function to be used for the file." (or (nth 1 (flymake-get-file-name-mode-and-masks file-name)) 'flymake-simple-cleanup)) (defun flymake-get-real-file-name-function (file-name) ! (or (nth 2 (flymake-get-file-name-mode-and-masks file-name)) 'flymake-get-real-file-name)) (defvar flymake-find-buildfile-cache (flymake-makehash 'equal)) (defun flymake-get-buildfile-from-cache (dir-name) (gethash dir-name flymake-find-buildfile-cache)) (defun flymake-add-buildfile-to-cache (dir-name buildfile) (puthash dir-name buildfile flymake-find-buildfile-cache)) (defun flymake-clear-buildfile-cache () (clrhash flymake-find-buildfile-cache)) (defun flymake-find-buildfile (buildfile-name source-dir-name) ! "Find buildfile starting from current directory. Buildfile includes Makefile, build.xml etc. Return its file name if found, or nil if not found." (or (flymake-get-buildfile-from-cache source-dir-name) --- 311,355 ---- (flymake-log 3 "file %s, init=%s" file-name (car mode-and-masks)) mode-and-masks)) (defun flymake-get-init-function (file-name) ! "Return init function to be used for the file FILE-NAME." (let* ((init-f (nth 0 (flymake-get-file-name-mode-and-masks file-name)))) ;;(flymake-log 0 "calling %s" init-f) ;;(funcall init-f (current-buffer)) init-f)) + (defun flymake-can-syntax-check-file (file-name) + "Determine whether we can syntax check FILE-NAME. + Return t if we can, nil if we cannot." + (if (flymake-get-init-function file-name) t nil)) + (defun flymake-get-cleanup-function (file-name) ! "Return cleanup function to be used for the file FILE-NAME." (or (nth 1 (flymake-get-file-name-mode-and-masks file-name)) 'flymake-simple-cleanup)) (defun flymake-get-real-file-name-function (file-name) ! "Return function that translates FILE-NAME to real file name." ! (or (nth 4 (flymake-get-file-name-mode-and-masks file-name)) 'flymake-get-real-file-name)) (defvar flymake-find-buildfile-cache (flymake-makehash 'equal)) (defun flymake-get-buildfile-from-cache (dir-name) + "Look up DIR-NAME in cache and return its associated value. + If DIR-NAME is not found, return nil." (gethash dir-name flymake-find-buildfile-cache)) (defun flymake-add-buildfile-to-cache (dir-name buildfile) + "Associate DIR-NAME with BUILDFILE in the buildfile cache." (puthash dir-name buildfile flymake-find-buildfile-cache)) (defun flymake-clear-buildfile-cache () + "Clear the buildfile cache." (clrhash flymake-find-buildfile-cache)) (defun flymake-find-buildfile (buildfile-name source-dir-name) ! "Find BUILDFILE-NAME starting from current directory. Buildfile includes Makefile, build.xml etc. Return its file name if found, or nil if not found." (or (flymake-get-buildfile-from-cache source-dir-name) *************** Return its file name if found, or nil if *** 344,350 **** nil))))) (defun flymake-fix-file-name (name) ! "Replace all occurrences of '\' with '/'." (when name (setq name (expand-file-name name)) (setq name (abbreviate-file-name name)) --- 364,370 ---- nil))))) (defun flymake-fix-file-name (name) ! "Replace all occurrences of '\' with '/' in filename NAME." (when name (setq name (expand-file-name name)) (setq name (abbreviate-file-name name)) *************** Return t if so, nil if not." *** 371,377 **** (defvar flymake-included-file-name) (defun flymake-find-possible-master-files (file-name master-file-dirs masks) ! "Find (by name and location) all possible master files. Master files include .cpp and .c for .h. Files are searched for starting from the .h directory and max max-level parent dirs. File contents are not checked." --- 391,397 ---- (defvar flymake-included-file-name) (defun flymake-find-possible-master-files (file-name master-file-dirs masks) ! "Find (by FILE-NAME and MASTER-FILE-DIRS) all possible master files. Master files include .cpp and .c for .h. Files are searched for starting from the .h directory and max max-level parent dirs. File contents are not checked." *************** instead of reading master file from disk *** 516,522 **** (current-buffer))) (defun flymake-check-include (source-file-name inc-name include-dirs) ! "Check if SOURCE-FILE-NAME can be found in include path. Return t if it can be found via include path using INC-NAME." (if (file-name-absolute-p inc-name) (flymake-same-files source-file-name inc-name) --- 536,542 ---- (current-buffer))) (defun flymake-check-include (source-file-name inc-name include-dirs) ! "Check if SOURCE-FILE-NAME can be found in INCLUDE-DIRS. Return t if it can be found via include path using INC-NAME." (if (file-name-absolute-p inc-name) (flymake-same-files source-file-name inc-name) *************** Return t if so, nil if not." *** 537,543 **** (get-buffer buffer-name)))) (defun flymake-create-master-file (source-file-name patched-source-file-name get-incl-dirs-f create-temp-f masks include-regexp) ! "Save SOURCE-FILE-NAME with a different name. Find master file, patch and save it." (let* ((possible-master-files (flymake-find-possible-master-files source-file-name flymake-master-file-dirs masks)) (master-file-count (length possible-master-files)) --- 557,563 ---- (get-buffer buffer-name)))) (defun flymake-create-master-file (source-file-name patched-source-file-name get-incl-dirs-f create-temp-f masks include-regexp) ! "Save SOURCE-FILE-NAME with a different name PATCHED-SOURCE-FILE-NAME. Find master file, patch and save it." (let* ((possible-master-files (flymake-find-possible-master-files source-file-name flymake-master-file-dirs masks)) (master-file-count (length possible-master-files)) *************** Find master file, patch and save it." *** 571,576 **** --- 591,598 ---- nil)))) (defun flymake-save-buffer-in-file (file-name) + "Save the entire buffer contents into file FILE-NAME. + It also creates optionally any nonexistent parent directories." (make-directory (file-name-directory file-name) 1) (write-region nil nil file-name nil 566) (flymake-log 3 "saved buffer %s in file %s" (buffer-name) file-name)) *************** Use CREATE-TEMP-F for creating temp copy *** 1842,1844 **** --- 1864,1868 ---- (provide 'flymake) ;;; flymake.el ends here + + ;; LocalWords: DIRS POS odl tex init GNUmakefile Makefile