branch: externals/csharp-mode commit f4afe09ede8a9f0e428097a61b9a4f02b3a5fcc0 Author: Jesse Black <jesse.w.bl...@gmail.com> Commit: Jesse Black <jesse.w.bl...@gmail.com>
remove flymake integration, closes #8 --- csharp-mode.el | 879 +-------------------------------------------------------- 1 file changed, 2 insertions(+), 877 deletions(-) diff --git a/csharp-mode.el b/csharp-mode.el index a41a956..725ae92 100644 --- a/csharp-mode.el +++ b/csharp-mode.el @@ -28,8 +28,8 @@ ;;; Commentary: ;; ;; This is a major mode for editing C# code. It performs automatic -;; indentation of C# syntax; font locking; and integration with compile.el; -;; flymake.el; yasnippet.el; and imenu.el. +;; indentation of C# syntax; font locking; and integration with +;; yasnippet.el; and imenu.el. ;; ;; csharp-mode requires CC Mode 5.30 or later. It works with ;; cc-mode 5.31.3, which is current at this time. @@ -50,18 +50,6 @@ ;; ;; - intelligent insertion of matched pairs of curly braces. ;; -;; - compile tweaks. Infers the compile command from special comments -;; in the file header. Also, sets the regex for next-error, so that -;; compile.el can handle csc.exe output. -;; -;; - flymake integration -;; - select flymake command from code comments -;; - infer flymake command otherwise (presence of makefile, etc) -;; - Turn off query-on-exit-flag for the flymake process. -;; - define advice to flymake-goto-line , to allow it to goto the -;; appropriate column for the error on a given line. This works -;; with `flymake-goto-next-error' etc. -;; ;; - yasnippet integration ;; - preloaded snippets ;; @@ -89,11 +77,8 @@ ;; "function that runs when csharp-mode is initialized for a buffer." ;; (turn-on-auto-revert-mode) ;; (setq indent-tabs-mode nil) -;; (require 'flymake) -;; (flymake-mode 1) ;; (require 'yasnippet) ;; (yas/minor-mode-on) -;; (require 'rfringe) ;; ...insert more code here... ;; ...including any custom key bindings you might want ... ;; ) @@ -107,87 +92,6 @@ ;; default keybindings and the highlights of the mode. ;; ;; -;; Flymake Integration -;; ---------------------------- -;; -;; You can use flymake with csharp mode to automatically check the -;; syntax of your csharp code, and highlight errors. To do so, add a -;; comment line like this to each .cs file that you use flymake with: -;; -;; // flymake: c:\.net3.5\csc.exe /t:module /nologo /R:Foo.dll @@FILE@@ -;; -;; That lines specifies a command "stub". Flymake appends the name of -;; the file to compile, and then runs the command to check -;; syntax. Flymake assumes that syntax errors will be noted in the -;; output of the command in a form that fits one of the regexs in the -;; `compilation-error-regexp-alist-alist'. Check the flymake module for -;; more information on that. -;; -;; Some rules for the command: -;; -;; 1. it must appear all on a single line. -;; -;; 2. csharp-mode generally looks for the marker line in the first N -;; lines of the file, where N is set in -;; `csharp-cmd-line-limit'. See the documentation on that -;; variable for more information. -;; -;; 3. the command SHOULD use @@FILE@@ in place of the name of the -;; source file to be compiled, normally the file being edited. -;; This is because normally flymake saves a copy of the buffer -;; into a temporary file with a unique name, and then compiles -;; that temporary file. The token @@FILE@@ is replaced by -;; csharp-mode with the name of the temporary file created by -;; flymake, before invoking the command. -;; -;; 4. The command should include /R options specifying external -;; libraries that the code depends on. -;; -;; If you have no external dependencies, then you need not specify any -;; flymake command at all. csharp-mode will implicitly act as if you had -;; specified the command: -;; -;; // flymake: c:\.net3.5\csc.exe /t:module /nologo @@FILE@@ -;; -;; -;; If you use csc.exe as the syntax check tool (as almost everyone -;; will), the /t:module is important. csharp-mode assumes that the -;; syntax-check compile command will produce a file named -;; NAME.netmodule, which is the default when using /t:module. (Remember -;; than NAME is dynamically generated). csharp-mode will remove the -;; generated netmodule file after the syntax check is complete. If you -;; don't specify /t:module, then csharp-mode won't know what file to -;; delete. -;; -;; csharp-mode also fiddles with some other flymake things. In -;; particular it: adds .cs to the flymake "allowed filename masks"; -;; adds parsing for csc error messages; and adds advice to the error -;; parsing logic. This all should be pretty benign for all other -;; flymake buffers. But it might not be. -;; -;; You can explicitly turn the flymake integration for C# off by -;; setting `csharp-want-flymake-fixup' to nil. -;; -;; -;; Compile Integration -;; ---------------------------- -;; -;; csharp-mode binds the function `csharp-invoke-compile-interactively' -;; to "\C-x\C-e" . This function attempts to intellgently guess the -;; format of the compile command to use for a buffer. It looks in the -;; comments at the head of the buffer for a line that begins with -;; compile: . If found, csharp-mode suggests the text that follows as -;; the compilation command when running `compile' . If such a line is -;; not found, csharp-mode falls back to a msbuild or nmake command. -;; See the documentation on `csharp-cmd-line-limit' for further -;; information. -;; -;; Also, csharp-mode installs an error regexp for csc.exe into -;; `compilation-error-regexp-alist-alist', which allows `next-error' -;; and `previous-error' (defined in compile.el) to navigate to the next -;; and previous compile errors in the cs buffer, after you've run `compile'. -;; -;; ;; YASnippet integration ;; ----------------------------- ;; @@ -1911,12 +1815,6 @@ Most other csharp functions are not instrumented. ;;;###autoload -(defcustom csharp-want-flymake-fixup t - "*Whether to enable the builtin C# support for flymake. This is meaningful -only if flymake is loaded." - :type 'boolean :group 'csharp) - -;;;###autoload (defcustom csharp-want-yasnippet-fixup t "*Whether to enable the builtin C# support for yasnippet. This is meaningful only if flymake is loaded." @@ -1929,102 +1827,6 @@ only if flymake is loaded." :type 'boolean :group 'csharp) -;;;###autoload -(defcustom csharp-make-tool "nmake.exe" - "*The make tool to use. Defaults to nmake, found on path. Specify -a full path or alternative program name, to tell csharp-mode to use -a different make tool in compile commands. - -See also, `csharp-msbuild-tool'. - -" - :type 'string :group 'csharp) - - -;;;###autoload -(defcustom csharp-msbuild-tool "msbuild.exe" - "*The tool to use to build .csproj files. Defaults to msbuild, found on -path. Specify a full path or alternative program name, to tell csharp-mode -to use a different make tool in compile commands. - -See also, `csharp-make-tool'. - -" - :type 'string :group 'csharp) - - -;;;###autoload -(defcustom csharp-cmd-line-limit 28 - "The number of lines at the top of the file to look in, to find -the command that csharp-mode will use to compile the current -buffer, or the command \"stub\" that csharp-mode will use to -check the syntax of the current buffer via flymake. - -If the value of this variable is zero, then csharp-mode looks -everywhere in the file. If the value is positive, then only in -the first N lines. If negative, then only in the final N lines. - -The line should appear in a comment inside the C# buffer. - - -Compile --------- - -In the case of compile, the compile command must be prefixed with -\"compile:\". For example, - - // compile: csc.exe /r:Hallo.dll Arfie.cs - - -This command will be suggested as the compile command when the -user invokes `compile' for the first time. - - -Flymake --------- - -In the case of flymake, the command \"stub\" string must be -prefixed with \"flymake:\". For example, - - // flymake: DOTNETDIR\csc.exe /target:netmodule /r:foo.dll @@FILE@@ - -In the case of flymake, the string should NOT include the name of -the file for the buffer being checked. Instead, use the token -@@FILE@@ . csharp-mode will replace this token with the name of -the source file to compile, before passing the command to flymake -to run it. - -If for some reason the command is invalid or illegal, flymake -will report an error and disable itself. - -It might be handy to run fxcop, for example, via flymake. - - // flymake: fxcopcmd.exe /c /f:MyLibrary.dll - - - -In all cases ------------- - -Be sure to specify the proper path for your csc.exe, whatever -version that might be, or no path if you want to use the system -PATH search. - -If the buffer depends on external libraries, then you will want -to include /R arguments to that csc.exe command. - -To be clear, this variable sets the number of lines to search for -the command. This cariable is an integer. - -If the marker string (either \"compile:\" or \"flymake:\" -is present in the given set of lines, csharp-mode will take -anything after the marker string as the command to run. - -" - :type 'integer :group 'csharp) - - - (defconst csharp-font-lock-keywords-1 (c-lang-const c-matchers-1 csharp) "Minimal highlighting for C# mode.") @@ -2065,31 +1867,6 @@ anything after the marker string as the command to run. "indicates whether yasnippet has been patched for use with csharp. Intended for internal use only.") -(defvar csharp--flymake-has-been-installed nil - "one-time use boolean, to check whether csharp tweaks for flymake (advice -etc) have been installed.") - -(defvar csharp-flymake-csc-arguments - (list "/t:module" "/nologo") - "A list of arguments to use with the csc.exe -compiler, when using flymake with a -direct csc.exe build for syntax checking purposes.") - - -(defvar csharp-flymake-aux-error-info nil - "a list of auxiliary flymake error info items. Each item in the -list is a pair, consisting of a line number and a column number. -This info is set by advice to flymake-parse-line, and used by -advice attached to flymake-goto-line, to navigate to the proper -error column when possible. ") - - -(defvar csharp-flymake-csc-error-pattern - "^[ \t]*\\([_A-Za-z0-9][^(]+\\.cs\\)(\\([0-9]+\\)[,]\\([0-9]+\\)) ?: \\(\\(error\\|warning\\) +:? *C[SA][0-9]+ *:[ \t\n]*\\(.+\\)\\)" - "The regex pattern for C# compiler error messages. Follows -the same form as an entry in `flymake-err-line-patterns'. The -value is a STRING, a regex.") - ;; TODO ;; Defines our constant for finding attributes. ;;(defconst csharp-attribute-regex "\\[\\([XmlType]+\\)(") @@ -2108,576 +1885,6 @@ value is a STRING, a regex.") ;; ================================================================== - - - -;; ======================================================================== -;; Flymake integration - -(defun csharp-flymake-init () - (csharp-flymake-init-impl - 'flymake-create-temp-inplace t t 'csharp-flymake-get-cmdline)) - -(defun csharp-flymake-init-impl (create-temp-f use-relative-base-dir use-relative-source get-cmdline-f) - "Create syntax check command line for a directly checked source file. -Use CREATE-TEMP-F for creating temp copy." - (let* ((args nil) - (temp-source-file-name (flymake-init-create-temp-buffer-copy create-temp-f))) - (setq args (flymake-get-syntax-check-program-args - temp-source-file-name "." - use-relative-base-dir use-relative-source - get-cmdline-f)) - args)) - - -(defun csharp-flymake-cleanup () - "Delete the temporary .netmodule file created in syntax checking -a C# buffer, then call through to flymake-simple-cleanup." - - (if flymake-temp-source-file-name - (progn - (let* ((netmodule-name - (concat (file-name-sans-extension flymake-temp-source-file-name) - ".netmodule")) - (expanded-netmodule-name (expand-file-name netmodule-name "."))) - (if (file-exists-p expanded-netmodule-name) - (flymake-safe-delete-file expanded-netmodule-name))) - )) - (flymake-simple-cleanup)) - - -(defun csharp-split-string-respecting-quotes (s) - "splits a string into tokens, respecting double quotes -For example, the string 'This is \"a string\"' will be split into 3 tokens. - -More pertinently, the string - 'csc /t:module /R:\"c:\abba dabba\dooo\Foo.dll\"' - -...will be split into 3 tokens. - -This fn also removes quotes from the tokens that have them. This is for -compatibility with flymake and the process-start fn. - -" - (let ((local-s s) - (my-re-1 "[^ \"]*\"[^\"]+\"\\|[^ \"]+") - (my-re-2 "\\([^ \"]*\\)\"\\([^\"]+\\)\"") - (tokens)) - (while (string-match my-re-1 local-s) - (let ((token (match-string 0 local-s)) - (remainder (substring local-s (match-end 0)))) - (if (string-match my-re-2 token) - (setq token (concat (match-string 1 token) (match-string 2 token)))) - ;;(message "token: %s" token) - (setq tokens (append tokens (list token))) - (setq local-s remainder))) - tokens)) - - -(defun csharp-get-value-from-comments (marker-string line-limit) - "gets a string from the header comments in the current buffer. - -This is used to extract the flymake command and the compile -command from the comments. - -It looks for \"marker-string:\" and returns the string that -follows it, or returns nil if that string is not found. - -eg, when marker-string is \"flymake\", and the following -string is found at the top of the buffer: - - flymake: csc.exe /r:Hallo.dll - -...then this command will return the string - - \"csc.exe /r:Hallo.dll\" - -It's ok to have whitespace between the marker and the following -colon. - -" - - (let (start search-limit found) - ;; determine what lines to look in - (save-excursion - (save-restriction - (widen) - (cond ((> line-limit 0) - (goto-char (setq start (point-min))) - (forward-line line-limit) - (setq search-limit (point))) - ((< line-limit 0) - (goto-char (setq search-limit (point-max))) - (forward-line line-limit) - (setq start (point))) - (t ;0 => no limit (use with care!) - (setq start (point-min)) - (setq search-limit (point-max)))))) - - ;; look in those lines - (save-excursion - (save-restriction - (widen) - (let ((re-string - (concat "\\b" marker-string "[ \t]*:[ \t]*\\(.+\\)$"))) - (if (and start - (< (goto-char start) search-limit) - (re-search-forward re-string search-limit 'move)) - - (buffer-substring-no-properties - (match-beginning 1) - (match-end 1)))))))) - - - - -(defun csharp-replace-command-tokens (explicitly-specified-command) - "Replace tokens in the flymake or compile command extracted from the -buffer, to allow specification of the original and modified -filenames. - - @@ORIG@@ - gets replaced with the original filename - @@FILE@@ - gets replaced with the name of the temporary file - created by flymake - -" - (let ((massaged-command explicitly-specified-command)) - (if (string-match "@@SRC@@" massaged-command) - (setq massaged-command - (replace-match - (file-relative-name flymake-temp-source-file-name) t t massaged-command))) - (if (string-match "@@ORIG@@" massaged-command) - (setq massaged-command - (replace-match - (file-relative-name buffer-file-name) t t massaged-command))) - massaged-command)) - - -;;(setq flymake-log-level 3) - -(defun csharp-flymake-get-final-csc-arguments (initial-arglist) - "Gets the command used by csc.exe for flymake runs. -This may inject a /t:module into an arglist, where it is not -present. - -This fn burps if a different /t: argument is found. - -" - (interactive) - (let ((args initial-arglist) - arg - (found nil)) - (while args - (setq arg (car args)) - (cond - ((string-equal arg "/t:module") (setq found t)) - ((string-match "^/t:" arg) - (setq found t) - (message "csharp-mode: WARNING /t: option present in arglist, and not /t:module; fix this."))) - - (setq args (cdr args))) - - (setq args - (if found - initial-arglist - (append (list "/t:module") initial-arglist))) - - (if (called-interactively-p 'any) - (message "result: %s" (prin1-to-string args))) - - args)) - - -(defun csharp-flymake-get-cmdline (source base-dir) - "Gets the cmd line for running a flymake session in a C# buffer. -This gets called by flymake itself. - -The fn looks in the buffer for a line that looks like: - - flymake: <command goes here> - - (It should be embedded into a comment) - -Typically the command will be a line that runs nmake.exe, -msbuild.exe, or csc.exe, with various options. It should -eventually run the CSC.exe compiler, or something else that emits -error messages in the same form as the C# compiler, like FxCopCmd.exe - -Some notes on implementation: - - 1. csharp-mode copies the buffer to a temporary file and - compiles *that*. This temporary file has a different name - than the actual file name for the buffer - _flymake gets - appended to the basename. Therefore, you should specify - Foo_flymake.cs for the filename, if you want to explicitly - refer to it. - - If you want to refer to it implicitly, you can use the special - token \"@@SRC@@\" in the command. It will get replaced with the - name of the temporary file at runtime. If you want to refer to - the original name of the buffer, use @@ORIG@@. - - 2. In general, when running the compiler, you should use a - target type of \"module\" (eg, /t:module) to allow - csharp-mode to clean up the products of the build. - - 3. See `csharp-cmd-line-limit' for a way to restrict where - csharp-mode will search for the command. - - 4. If this string is not found, then this fn will fallback to - a generic, generated csc.exe command. - -" - (let ((explicitly-specified-command - (csharp-get-value-from-comments "flymake" csharp-cmd-line-limit))) - - (cond - (explicitly-specified-command - - ;; the marker string was found in the buffer - (let ((tokens (csharp-split-string-respecting-quotes - (csharp-replace-command-tokens explicitly-specified-command)))) - - (list (car tokens) (cdr tokens)))) - - ;; ;; implicitly append? the name of the temporary source file - ;; (list (car tokens) (append (cdr tokens) (list flymake-temp-source-file-name))))) - - (t - ;; fallback - (list "csc.exe" - (append (csharp-flymake-get-final-csc-arguments - csharp-flymake-csc-arguments) - (list source))))))) - - -;; (defun csharp-flymake-get-cmdline (source base-dir) -;; "Gets the cmd line for running a flymake session in a C# buffer. -;; This gets called by flymake itself. -;; -;; The fn looks in the buffer for a line that looks like: -;; -;; flymake: <command goes here> -;; -;; (It should be embedded into a comment) -;; -;; Typically the command will be a line that runs nmake.exe, -;; msbuild.exe, or cscc.exe, with various options. It should -;; eventually run the CSC.exe compiler, or something else that emits -;; error messages in the same form as the C# compiler. -;; -;; In general, when running the compiler, you should use a target -;; type of \"module\" (eg, /t:module) to allow csharp-mode to -;; clean up the products of the build. -;; -;; See `csharp-cmd-line-limit' for a way to restrict where -;; csharp-mode will search for the command. -;; -;; If this string is not found, then this fn will fallback to a -;; generic, generated csc.exe command. -;; -;; " -;; (let ((explicitly-specified-command -;; (let ((line-limit csharp-cmd-line-limit) -;; start search-limit found) -;; ;; determine what lines to look in -;; (save-excursion -;; (save-restriction -;; (widen) -;; (cond ((> line-limit 0) -;; (goto-char (setq start (point-min))) -;; (forward-line line-limit) -;; (setq search-limit (point))) -;; ((< line-limit 0) -;; (goto-char (setq search-limit (point-max))) -;; (forward-line line-limit) -;; (setq start (point))) -;; (t ;0 => no limit (use with care!) -;; (setq start (point-min)) -;; (setq search-limit (point-max)))))) -;; -;; ;; look in those lines -;; (save-excursion -;; (save-restriction -;; (widen) -;; (if (and start -;; (< (goto-char start) search-limit) -;; (re-search-forward "\\bflymake-command[ \t]*:[ \t]*\\(.+\\)$" search-limit 'move)) -;; -;; (buffer-substring-no-properties -;; (match-beginning 1) -;; (match-end 1)))))))) -;; -;; (cond -;; (explicitly-specified-command -;; ;; the marker string was found in the buffer -;; (let ((tokens (csharp-split-string-respecting-quotes -;; explicitly-specified-command))) -;; ;; implicitly append the name of the temporary source file -;; (list (car tokens) (append (cdr tokens) (list flymake-temp-source-file-name))))) -;; -;; (t -;; ;; fallback -;; (list "csc.exe" -;; (append (csharp-flymake-get-final-csc-arguments -;; csharp-flymake-csc-arguments) -;; (list source))))))) - - - - - -(defun csharp-flymake-install () - "Change flymake variables and fns to work with C#. - -This fn does these things: - -1. add a C# entry to the flymake-allowed-file-name-masks, - or replace it if it already exists. - -2. add a C# entry to flymake-err-line-patterns. - This isn't strictly necessary because of item #4. - -3. override the definition for flymake-process-sentinel - to NOT check the process status on exit. MSBuild.exe - sets a non-zero status code when compile errors occur, - which causes flymake to disable itself with the regular - flymake-process-sentinel. - -4. redefine flymake-start-syntax-check-process to unset the - query-on-exit flag for flymake processes. This allows emacs to - exit even if flymake is currently running. - -5. provide advice to flymake-parse-line and - flymake-parse-err-lines, specifically set up for C# - buffers. This allows optimized searching for errors in csc.exe - output, and storing column numbers, for use in #6. - -6. define advice to flymake-goto-line , to allow it to goto the - appropriate column for the error on a given line. This advice - looks in flymake-er-info, a list, and uses the heuristic that - the first error that matches the given line number, is the error - we want. This will break if there is more than one error on a - single line. - -" - - (flymake-log 2 "csharp-flymake-install") - - (or csharp--flymake-has-been-installed - (progn - - ;; 1. add a C# entry to the flymake-allowed-file-name-masks - (let* ((key "\\.cs\\'") - (csharpentry (assoc key flymake-allowed-file-name-masks))) - (if csharpentry - (setcdr csharpentry '(csharp-flymake-init csharp-flymake-cleanup)) - (add-to-list - 'flymake-allowed-file-name-masks - (list key 'csharp-flymake-init 'csharp-flymake-cleanup)))) - - - ;; 2. add a C# entry to flymake-err-line-patterns - ;; - ;; The value of each entry is a list, (STRING IX1 IX2 IX3 IX4), where - ;; STRING is the regex, and the other 4 values are indexes into the - ;; regex captures for the filename, line, column, and error text, - ;; respectively. - (add-to-list - 'flymake-err-line-patterns - (list csharp-flymake-csc-error-pattern 1 2 3 4)) - - - - ;; 3. override the definition for flymake-process-sentinel - ;; - ;; DPC - 2011 Feb 26 - ;; Redefining a function is a bit unusual, but I think it is necessary - ;; to remove the check on process exit status. For VBC.exe, it gives - ;; a 1 status when compile errors result. Likewise msbuild.exe. This - ;; means flymake turns itself off, which we don't want. This really - ;; ought to be tunable in flymake, but I guess no one asked for that - ;; feature yet. - (defun flymake-process-sentinel (process event) - "Sentinel for syntax check buffers." - (when (memq (process-status process) '(signal exit)) - (let* ((exit-status (process-exit-status process)) - (command (process-command process)) - (source-buffer (process-buffer process)) - (cleanup-f (flymake-get-cleanup-function (buffer-file-name source-buffer)))) - - (flymake-log 2 "process %d exited with code %d" - (process-id process) exit-status) - (condition-case err - (progn - (flymake-log 3 "cleaning up using %s" cleanup-f) - (when (buffer-live-p source-buffer) - (with-current-buffer source-buffer - (funcall cleanup-f))) - - (delete-process process) - (setq flymake-processes (delq process flymake-processes)) - - (when (buffer-live-p source-buffer) - (with-current-buffer source-buffer - - (flymake-parse-residual) - ;;(flymake-post-syntax-check exit-status command) - (flymake-post-syntax-check 0 command) - (setq flymake-is-running nil)))) - (error - (let ((err-str (format "Error in process sentinel for buffer %s: %s" - source-buffer (error-message-string err)))) - (flymake-log 0 err-str) - (with-current-buffer source-buffer - (setq flymake-is-running nil)))))))) - - - ;; 4. redefine this fn - the reason is to allow exit without query on - ;; flymake processes. Not sure why this is not the default. - (defun flymake-start-syntax-check-process (cmd args dir) - "Start syntax check process." - (let* ((process nil)) - (condition-case err - (progn - (when dir - (let ((default-directory dir)) - (flymake-log 3 "starting process on dir %s" default-directory))) - (setq process (apply 'start-process "flymake-proc" (current-buffer) cmd args)) - - ;; dino - exit without query on active flymake processes - (set-process-query-on-exit-flag process nil) - - (set-process-sentinel process 'flymake-process-sentinel) - (set-process-filter process 'flymake-process-filter) - (push process flymake-processes) - - (setq flymake-is-running t) - (setq flymake-last-change-time nil) - (setq flymake-check-start-time (flymake-float-time)) - - (flymake-report-status nil "*") - (flymake-log 2 "started process %d, command=%s, dir=%s" - (process-id process) (process-command process) - default-directory) - process) - (error - (let* ((err-str (format "Failed to launch syntax check process '%s' with args %s: %s" - cmd args (error-message-string err))) - (source-file-name buffer-file-name) - (cleanup-f (flymake-get-cleanup-function source-file-name))) - (flymake-log 0 err-str) - (funcall cleanup-f) - (flymake-report-fatal-status "PROCERR" err-str)))))) - - - ;; 5. define some advice for the error parsing - (defadvice flymake-parse-err-lines (before - csharp-flymake-parse-line-patch-1 - activate compile) - (if (string-match "\\.[Cc][Ss]$" (file-relative-name buffer-file-name)) - ;; clear the auxiliary line information list, when a new parse - ;; starts. - (setq csharp-flymake-aux-error-info nil))) - - (defadvice flymake-parse-line (around - csharp-flymake-parse-line-patch-2 - activate compile) - ;; This advice will run in all buffers. Let's may sure we - ;; actually execute the important stiff only when a C# buffer is active. - (if (string-match "\\.[Cc][Ss]$" (file-relative-name buffer-file-name)) - - (let (raw-file-name - e-text - result - (pattern (list csharp-flymake-csc-error-pattern 1 2 3 4)) - (line-no 0) - (col-no 0) - (err-type "e")) - (if (string-match (car pattern) line) - (let* ((file-idx (nth 1 pattern)) - (line-idx (nth 2 pattern)) - (col-idx (nth 3 pattern)) - (e-idx (nth 4 pattern))) - (flymake-log 3 "parse line: fx=%s lx=%s ex=%s" - file-idx line-idx e-idx) - (setq raw-file-name (if file-idx (match-string file-idx line) nil)) - (setq line-no (if line-idx (string-to-number (match-string line-idx line)) 0)) - (setq col-no (if col-idx (string-to-number (match-string col-idx line)) 0)) - (setq e-text (if e-idx - (match-string e-idx line) - (flymake-patch-e-text (substring line (match-end 0))))) - (or e-text (setq e-text "<no error text>")) - (if (and e-text (string-match "^[wW]arning" e-text)) - (setq err-type "w")) - (flymake-log 3 "parse line: fx=%s/%s lin=%s/%s col=%s/%s text=%s" - file-idx raw-file-name - line-idx line-no - col-idx (prin1-to-string col-no) - e-text) - - ;; add one entry to the list of auxiliary error information. - (add-to-list 'csharp-flymake-aux-error-info - (list line-no col-no)) - - (setq ad-return-value - (flymake-ler-make-ler raw-file-name line-no err-type e-text nil)) - ))) - - ;; else - not in a C# buffer - ad-do-it)) - - - ;; 6. finally, define some advice for the line navigation. It moves - ;; to the proper column, given the line number containing the - ;; error. It first calls the normal `flymake-goto-line', and assumes - ;; that the result is that the cursor is on the line that contains the - ;; error. At exit from that fn, the column is not important. This advice - ;; sets the column. - (defadvice flymake-goto-line (around - csharp-flymake-goto-line-patch - activate compile) - ;; This advice will run in all buffers. Let's may sure we - ;; actually execute the important stuff only when a C# buffer is active. - ad-do-it - (if (string-match "\\.[Cc][Ss]$" (file-relative-name buffer-file-name)) - (let* ((lno (ad-get-arg 0)) - (epair (assoc lno csharp-flymake-aux-error-info))) - (if epair - (forward-char (- (cadr epair) (current-column) 1)))))) - - - ;; 7. finally, set the flag - (setq csharp--flymake-has-been-installed t)))) - - - -;; Need to temporarily turn off flymake while reverting. -;; There' some kind of race-condition where flymake is trying -;; to compile while the buffer is being changed, and that -;; causes flymake to choke. -(defadvice revert-buffer (around - csharp-advise-revert-buffer - activate compile) - (let ((is-flymake-enabled - (and (fboundp 'flymake-mode) - flymake-mode))) - ;; disable - (if is-flymake-enabled - (flymake-mode-off)) - - ;; revert - ad-do-it - - ;; enable - (if is-flymake-enabled - (flymake-mode-on)))) - -;; ++++++++++++++++++++++ - - - - ;; ======================================================================== ;; moving @@ -5383,10 +4590,7 @@ To run your own logic after csharp-mode starts, do this: (turn-on-font-lock) (turn-on-auto-revert-mode) ;; helpful when also using Visual Studio (setq indent-tabs-mode nil) ;; tabs are evil - (flymake-mode 1) (yas/minor-mode-on) - (require 'rfringe) ;; handy for flymake - (require 'flymake-cursor) ;; also handy for flymake ....your own code here... ) (add-hook 'csharp-mode-hook 'my-csharp-mode-fn t) @@ -5395,62 +4599,6 @@ To run your own logic after csharp-mode starts, do this: The function above is just a suggestion. -Compile integration: -======================== - -csharp-mode binds the function `csharp-invoke-compile-interactively' to -\"\C-x\C-e\" . This function attempts to intellgently guess the format of the -compile command to use for a buffer. It looks in the comments at the head of -the buffer for a line that begins with compile: . For exammple: - - // compile: csc.exe /t:library /r:Mylib.dll Foo.cs - -If csharp-mode finds a line like this, it will suggest the text that follows -as the compilation command when running `compile' for the first time. If such -a line is not found, csharp-mode falls back to a msbuild or nmake command. -See the documentation on `csharp-cmd-line-limit' for further information. If -you don't want this magic, then you can just run `compile' directly, rather -than `csharp-invoke-compile-interactively' . - -This mode will also automatically add a symbol and regexp to the -`compilation-error-regexp-alist' and`compilation-error-regexp-alist-alist' -respectively, for Csc.exe error and warning messages. If you invoke `compile', -then `next-error' should work properly for error messages produced by csc.exe. - - -Flymake Integraiton -======================== - -You can use flymake with csharp mode to automatically check the syntax of your -csharp code, and highlight errors. To do so, add a comment line like this to -each .cs file that you use flymake with: - - // flymake: csc.exe /t:module /R:Foo.dll @@FILE@@ - -csharp-mode replaces special tokens in the command with different values: - - @@ORIG@@ - gets replaced with the original filename - @@FILE@@ - gets replaced with the name of the temporary file - created by flymake. This is usually what you want in place of the - name of the file to be compiled. - -See the documentation on `csharp-cmd-line-limit' for further information. - -You may also want to run a syntax checker, like fxcop: - - // flymake: fxcopcmd.exe /c /F:MyLibrary.dll - -In this case you don't need either of the tokens described above. - -If the module has no external dependencies, then you need not specify any -flymake command at all. csharp-mode will implicitly act as if you had -specified the command: - - // flymake: csc.exe /t:module /nologo @@FILE@@ - -It looks for the EXE on the path. You can specify a full path if you like. - - YASnippet and IMenu Integraiton =============================== @@ -5496,29 +4644,6 @@ Key bindings: ;; analysis and similar things working. (c-common-init 'csharp-mode) - ;; compile - (local-set-key "\C-x\C-e" 'csharp-invoke-compile-interactively) - - ;; to allow next-error to work with csc.exe: - (setq compilation-scroll-output t) - - ;; csc.exe, the C# Compiler, produces errors like this: - ;; file.cs(6,18): error CS1006: Name of constructor must match name of class - (if (boundp 'compilation-error-regexp-alist-alist) - (progn - (add-to-list - 'compilation-error-regexp-alist-alist - '(ms-csharp "^[ \t]*\\([-_:A-Za-z0-9][^\n(]*\\.\\(?:cs\\|xaml\\)\\)(\\([0-9]+\\)[,]\\([0-9]+\\)) ?: \\(error\\|warning\\) CS[0-9]+:" 1 2 3)) - (add-to-list - 'compilation-error-regexp-alist - 'ms-csharp))) - - ;; flymake - (eval-after-load "flymake" - '(progn - (if csharp-want-flymake-fixup - (csharp-flymake-install)))) - (eval-after-load "yasnippet" '(progn (if csharp-want-yasnippet-fixup