2727
2828; ;; Commentary:
2929; ;
30- ; ; This is a major mode for editing C# code. It performs automatic
30+ ; ; This is a major mode for editing C# code. It performs automatic
3131; ; indentation of C# syntax; font locking; and integration with
3232; ; imenu.el.
3333; ;
6868; ; (append '(("\\ .cs$" . csharp-mode)) auto-mode-alist))
6969; ;
7070; ;
71- ; ; Optionally, define and register a mode-hook function. To do so, use
71+ ; ; Optionally, define and register a mode-hook function. To do so, use
7272; ; something like this in your .emacs file:
7373; ;
7474; ; (defun my-csharp-mode-fn ()
9191; ; imenu integration
9292; ; -----------------------------
9393; ;
94- ; ; This should just work. For those who don't know what imenu is, it
94+ ; ; This should just work. For those who don't know what imenu is, it
9595; ; allows navigation to different points within the file from an
9696; ; "Index" menu, in the window's menubar. csharp-mode computes the
9797; ; menu containing the namespaces, classes, methods, and so on, in the
295295; ; - Cleaned up dead code.
296296; ;
297297; ; 0.9.1 2016 ....
298- ; ; -
298+ ; ; -
299299; ;
300+ ; ;; Code:
300301
301302(require 'cc-mode )
303+ (require 'cc-fonts )
302304(require 'cl-lib )
303305
304306; ; prevent warnings like
@@ -378,7 +380,7 @@ This is used in particular by the verbatim-literal
378380string scanning.
379381
380382Most other csharp functions are not instrumented.
381- 0 = NONE, 1 = Info, 2 = VERBOSE, 3 = DEBUG, 4 = SHUTUP ALREADY. "
383+ 0 = NONE, 1 = Info, 2 = VERBOSE, 3 = DEBUG, 4 = SHUTUP ALREADY."
382384 :type 'integer
383385 :group 'csharp )
384386
@@ -462,7 +464,7 @@ Most other csharp functions are not instrumented.
462464It returns t if at a position where a virtual-semicolon is.
463465Otherwise nil.
464466
465- This is the C# version of the function. It gets set into
467+ This is the C# version of the function. It gets set into
466468the variable `c-at-vsemi-p-fn' .
467469
468470A vsemi is a cc-mode concept implying the end of a statement,
@@ -481,9 +483,7 @@ A vsemi appears in 2 cases in C#:
481483An example of the former is [WebMethod] or [XmlElement].
482484
483485Providing this function allows the indenting in csharp-mode
484- to work properly with code that includes attributes.
485-
486- "
486+ to work properly with code that includes attributes."
487487 (save-excursion
488488 (let ((pos-or-point (progn (if pos (goto-char pos)) (point ))))
489489
@@ -1121,7 +1121,7 @@ to work properly with code that includes attributes.
11211121 csharp ?@ )
11221122
11231123(defun csharp-mode-syntax-propertize-function (beg end )
1124- " Apply syntax table properties to special constructs.
1124+ " Apply syntax table properties to special constructs in region BEG to END .
11251125Currently handled:
11261126
11271127- Fontify verbatim literal strings correctly
@@ -1540,30 +1540,26 @@ This regexp is assumed to not match any non-operator identifier."
15401540
15411541
15421542(defun csharp--regexp (symbol )
1543- " Retrieves a regexp from the `csharp--regexp-alist' corresponding
1544- to the given symbol.
1545- "
1543+ " Retrieve a regexp from `csharp--regexp-alist' corresponding to SYMBOL."
15461544 (let ((elt (assoc symbol csharp--regexp-alist)))
15471545 (if elt (cadr elt) nil )))
15481546
15491547
15501548(defun csharp-move-back-to-beginning-of-block ()
1551- " Moves to the previous open curly.
1552- "
1549+ " Move to the previous open curly."
15531550 (interactive )
15541551 (re-search-backward " {" (point-min ) t ))
15551552
15561553
15571554(defun csharp--move-back-to-beginning-of-something (must-match &optional must-not-match )
1558- " Moves back to the open-curly that defines the beginning of *something*,
1559- defined by the given MUST-MATCH, a regexp which must match immediately
1560- preceding the curly. If MUST-NOT-MATCH is non-nil, it is treated
1561- as a regexp that must not match immediately preceding the curly.
1555+ " Move back to the open-curly that begin *something*.
1556+ *something* is defined by MUST-MATCH, a regexp which must match
1557+ immediately preceding the curly. If MUST-NOT-MATCH is non-nil,
1558+ it is treated as a regexp that must not match immediately
1559+ preceding the curly.
15621560
15631561This is a helper fn for `csharp-move-back-to-beginning-of-defun' and
1564- `csharp-move-back-to-beginning-of-class'
1565-
1566- "
1562+ `csharp-move-back-to-beginning-of-class' "
15671563 (interactive )
15681564 (let (done
15691565 (found (point ))
@@ -1582,12 +1578,11 @@ This is a helper fn for `csharp-move-back-to-beginning-of-defun' and
15821578
15831579
15841580(defun csharp-move-back-to-beginning-of-defun ()
1585- " Moves back to the open-curly that defines the beginning of the
1586- enclosing method. If point is outside a method, then move back to the
1581+ " Move back to the open-curly that start the enclosing method.
1582+ If point is outside a method, then move back to the
15871583beginning of the prior method.
15881584
1589- See also, `csharp-move-fwd-to-end-of-defun' .
1590- "
1585+ See also, `csharp-move-fwd-to-end-of-defun' ."
15911586 (interactive )
15921587 (cond
15931588
@@ -1613,27 +1608,26 @@ See also, `csharp-move-fwd-to-end-of-defun'.
16131608
16141609
16151610(defun csharp--on-defun-open-curly-p ()
1616- " return t when point is on the open-curly of a method."
1611+ " Return t when point is on the open-curly of a method."
16171612 (and (looking-at " {" )
16181613 (not (looking-back (csharp--regexp 'class-start ) nil ))
16191614 (not (looking-back (csharp--regexp 'namespace-start ) nil ))
16201615 (looking-back (csharp--regexp 'func-start ) nil )))
16211616
16221617
16231618(defun csharp--on-class-open-curly-p ()
1624- " return t when point is on the open-curly of a class."
1619+ " Return t when point is on the open-curly of a class."
16251620 (and (looking-at " {" )
16261621 (not (looking-back (csharp--regexp 'namespace-start ) nil ))
16271622 (looking-back (csharp--regexp 'class-start ) nil )))
16281623
16291624
16301625(defun csharp-move-fwd-to-end-of-defun ()
1631- " Moves forward to the close-curly that defines the end of the enclosing
1632- method. If point is outside a method, moves forward to the close-curly that
1626+ " Move forward to the close-curly that ends the enclosing method.
1627+ If point is outside a method, moves forward to the close-curly that
16331628defines the end of the next method.
16341629
1635- See also, `csharp-move-back-to-beginning-of-defun' .
1636- "
1630+ See also, `csharp-move-back-to-beginning-of-defun' ."
16371631 (interactive )
16381632
16391633 (let ((really-move
@@ -1695,12 +1689,11 @@ See also, `csharp-move-back-to-beginning-of-defun'.
16951689
16961690
16971691(defun csharp-move-back-to-beginning-of-class ()
1698- " Moves back to the open-curly that defines the beginning of the
1699- enclosing class. If point is outside a class, then move back to the
1692+ " Move back to the open-curly that begin the enclosing class.
1693+ If point is outside a class, then move back to the
17001694beginning of the prior class.
17011695
1702- See also, `csharp-move-fwd-to-end-of-defun' .
1703- "
1696+ See also, `csharp-move-fwd-to-end-of-defun' ."
17041697 (interactive )
17051698
17061699 (cond
@@ -1728,11 +1721,9 @@ See also, `csharp-move-fwd-to-end-of-defun'.
17281721
17291722
17301723(defun csharp-move-fwd-to-end-of-class ()
1731- " Moves forward to the close-curly that defines the end of the
1732- enclosing class.
1724+ " Move forward to the close-curly that ends the enclosing class.
17331725
1734- See also, `csharp-move-back-to-beginning-of-class' .
1735- "
1726+ See also, `csharp-move-back-to-beginning-of-class' ."
17361727 (interactive )
17371728 (let ((start (point ))
17381729 dest-char)
@@ -1748,11 +1739,9 @@ See also, `csharp-move-back-to-beginning-of-class'.
17481739
17491740
17501741(defun csharp-move-back-to-beginning-of-namespace ()
1751- " Moves back to the open-curly that defines the beginning of the
1752- enclosing namespace. If point is outside a namespace, then move back
1753- to the beginning of the prior namespace.
1754-
1755- "
1742+ " Move back to the open-curly that begins the enclosing namespace.
1743+ If point is outside a namespace, then move back
1744+ to the beginning of the prior namespace."
17561745 (interactive )
17571746 (cond
17581747
@@ -1983,20 +1972,20 @@ to the beginning of the prior namespace.
19831972 " ;" ) 1 ))))
19841973
19851974(defun csharp--imenu-get-pos (pair )
1986- " Takes a (title . position) cons-pair `PAIR' and returns position .
1975+ " Return `position' from a (title . position) cons-pair `PAIR' .
19871976
19881977 The position may be a integer, or a marker (as returned by
1989- imenu-indexing). This function ensures what is returned is an
1978+ imenu-indexing). This function ensures what is returned is an
19901979 integer which can be used for easy comparison."
19911980 (let ((pos (cdr pair)))
19921981 (if (markerp pos)
19931982 (marker-position pos)
19941983 pos)))
19951984
19961985(defun csharp--imenu-get-container (item containers previous )
1997- " Returns the container which `ITEM' belongs to.
1986+ " Return the container which `ITEM' belongs to.
19981987
1999- `ITEM' is a (title . position) cons-pair. `CONTAINERS' is a
1988+ `ITEM' is a (title . position) cons-pair. `CONTAINERS' is a
20001989 list of such. `PREVIOUS' is the name of the previous
20011990 container found when recursing through `CONTAINERS' .
20021991
@@ -2014,7 +2003,7 @@ to the beginning of the prior namespace.
20142003 (csharp--imenu-get-container item rest container)))))
20152004
20162005(defun csharp--imenu-get-container-name (item containers )
2017- " Returns the name of the container which `ITEM' belongs to.
2006+ " Return the name of the container which `ITEM' belongs to.
20182007
20192008 `ITEM' is a (title . position) cons-pair.
20202009 `CONTAINERS' is a list of such.
@@ -2032,7 +2021,7 @@ to the beginning of the prior namespace.
20322021 container-p1)))))
20332022
20342023(defun csharp--imenu-sort (items )
2035- " Sorts an imenu-index list `ITMES ' by the string-portion."
2024+ " Sort an imenu-index list `ITEMS ' by the string-portion."
20362025 (sort items (lambda (item1 item2 )
20372026 (string< (car item1) (car item2)))))
20382027
@@ -2051,7 +2040,7 @@ to the beginning of the prior namespace.
20512040 (concat type " " namespace " ." name)))))
20522041
20532042(defun csharp--imenu-get-class-nodes (classes namespaces )
2054- " Creates a new alist with classes as root nodes with namespaces added.
2043+ " Create a new alist with CLASSES as root nodes with NAMESPACES added.
20552044
20562045 Each class will have one imenu index-entry \" ( top)\" added by
20572046 default."
@@ -2068,7 +2057,7 @@ to the beginning of the prior namespace.
20682057 classes))
20692058
20702059(defun csharp--imenu-get-class-node (result item classes namespaces )
2071- " Gets the class-node which a `ITEM' should be inserted into in `RESULT' .
2060+ " Get the class-node in `RESULT' which an `ITEM' should be inserted into.
20722061
20732062 For this calculation, the original index items `CLASSES' and `NAMESPACES'
20742063 is needed."
@@ -2077,7 +2066,7 @@ to the beginning of the prior namespace.
20772066 (assoc class-name result)))
20782067
20792068(defun csharp--imenu-format-item-node (item type )
2080- " Formats a item with a specified type as a imenu item to be inserted into the index."
2069+ " Format an ITEM with a specified TYPE as an imenu item to be inserted into the index."
20812070 (cons
20822071 (concat " (" type " ) " (car item))
20832072 (cdr item)))
@@ -2091,7 +2080,7 @@ to the beginning of the prior namespace.
20912080 (nconc class-node (list item-node))))))
20922081
20932082(defun csharp--imenu-transform-index (index )
2094- " Transforms a imenu-index based on `IMENU-GENERIC-EXPRESSION' .
2083+ " Transform an imenu INDEX based on `IMENU-GENERIC-EXPRESSION' .
20952084
20962085 The resulting structure should be based on full type-names, with
20972086 type-members nested hierarchially below its parent.
@@ -2149,11 +2138,12 @@ to the beginning of the prior namespace.
21492138 (csharp--imenu-sort result)))
21502139
21512140(defun csharp--imenu-create-index-function ()
2141+ " Create an imenu index."
21522142 (csharp--imenu-transform-index
21532143 (imenu--generic-function csharp--imenu-expression)))
21542144
21552145(defun csharp--setup-imenu ()
2156- " Sets up `imenu' for `csharp-mode' ."
2146+ " Set up `imenu' for `csharp-mode' ."
21572147
21582148 ; ; There are two ways to do imenu indexing. One is to provide a
21592149 ; ; function, via `imenu-create-index-function' . The other is to
@@ -2187,13 +2177,12 @@ to the beginning of the prior namespace.
21872177; ; must live within csharp-mode itself.
21882178
21892179(defun csharp-maybe-insert-codedoc (arg )
2190-
2191- " Insert an xml code documentation template as appropriate, when
2192- typing slashes. This fn gets bound to / (the slash key), in
2180+ " Insert an xml code documentation template on third consecutive slash.
2181+ This fn gets bound to / (the slash key), in
21932182csharp-mode. If the slash being inserted is not the third
21942183consecutive slash, the slash is inserted as normal. If it is the
21952184third consecutive slash, then a xml code documentation template
2196- may be inserted in some cases. For example,
2185+ may be inserted in some cases. For example,
21972186
21982187 a <summary> template is inserted if the prior line is empty,
21992188 or contains only an open curly brace;
@@ -2208,13 +2197,15 @@ may be inserted in some cases. For example,
22082197
22092198In all other cases the slash is inserted as normal.
22102199
2200+ The prefix argument ARG is passed on to `self-insert-command'
2201+ when the code documentation template isn't triggered. This makes
2202+ sure that M-10 / still produces 10 consecutive slashes as expected.
2203+
22112204If you want the default cc-mode behavior, which implies no automatic
22122205insertion of xml code documentation templates, then use this in
22132206your `csharp-mode-hook' function:
22142207
2215- (local-set-key (kbd \" /\" ) 'c-electric-slash)
2216-
2217- "
2208+ (local-set-key (kbd \" /\" ) 'c-electric-slash)"
22182209 (interactive " *p" )
22192210 ; ;(message "csharp-maybe-insert-codedoc")
22202211 (let (
@@ -2410,7 +2401,7 @@ your `csharp-mode-hook' function:
24102401; ; ==================================================================
24112402
24122403(defun csharp-time ()
2413- " returns the time of day as a string. Used in the `csharp-log' function."
2404+ " Return the time of day as a string. Used in the `csharp-log' function."
24142405 (substring (current-time-string ) 11 19 )) ; 24-hr time
24152406
24162407
@@ -2432,6 +2423,7 @@ are the string substitutions (see `format')."
24322423(defadvice c-forward-objc-directive (around
24332424 csharp-mode-advice-2
24342425 compile activate)
2426+ " Make `c-forward-objc-directive' a no-op in `csharp-mode' ."
24352427 (if (c-major-mode-is 'csharp-mode )
24362428 nil
24372429 ad-do-it)
@@ -2752,6 +2744,7 @@ are the string substitutions (see `format')."
27522744; ; match name of class [c:\Users\user\project.csproj]
27532745
27542746(defun csharp--compilation-error-file-resolve ()
2747+ " Resolve an msbuild error to a (filename . dirname) cons cell."
27552748 ; ; http://stackoverflow.com/a/18049590/429091
27562749 (cons (match-string 1 ) (file-name-directory (match-string 4 ))))
27572750
0 commit comments