Skip to content

Commit

Permalink
Add casing support.
Browse files Browse the repository at this point in the history
  • Loading branch information
brownts committed Dec 6, 2024
1 parent 2f23e4c commit 0f8bb4e
Show file tree
Hide file tree
Showing 5 changed files with 657 additions and 7 deletions.
64 changes: 61 additions & 3 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ methods (e.g., regular expressions).

This major mode provides support for syntax highlighting, indentation,
navigation, Imenu, "which function" (i.e., displaying the current
function name in the mode line) and outlining (via
=outline-minor-mode=).
function name in the mode line), outlining (via =outline-minor-mode=)
and casing.

*Note*: This major mode is based on the Emacs 29 (or newer) built-in
tree-sitter support, not to be confused with the separate Emacs
Expand Down Expand Up @@ -320,6 +320,56 @@ order to create a category, a new category symbol should be added to
category symbol name. Refer to existing instances of this function to
understand how current category index functions are implemented.

* Casing

Functionality is provided to manage casing within a GNAT Project
buffer. This includes a number of commands to apply casing rules to
point, to a region or to the entire buffer. The commands can be used
interactively, but may also be useful in other ways (such as calling
the buffer casing command from the =buffer-save-hook=). An auto-casing
minor mode is also provided which performs case formatting as you
type.

- User Option: gpr-ts-mode-case-formatting ::
A set of casing rules, used by the casing commands and modes, which
apply category specific formatting and dictionaries.

- Command: gpr-ts-auto-case-mode ::
A minor mode which applies casing corrections as you type at each
word or subword boundary.

- Command: gpr-ts-mode-case-format-region ::
Applies formatting to the specified region for all items in the
region which match the case formatting categories specified in
=gpr-ts-mode-case-formatting=. When the region doesn't start or stop
exactly on a category boundary, the range is expanded to the
category boundary.

- Command: gpr-ts-mode-case-format-at-point ::
Applies formatting to point, assuming the item at point matches a
case formatting category specified in =gpr-ts-mode-case-formatting=.
When no category is matched, no formatting is applied.

- Command: gpr-ts-mode-case-format-buffer ::
Applies formatting to the entire buffer for all items in the buffer
which match the case formatting categories specified in
=gpr-ts-mode-case-formatting=.

- Command: gpr-ts-mode-case-format-dwim ::
A convenience command which will select between "region" and "at
point" formatting depending on whether a region is active in the
buffer.

If none of the existing casing categories are sufficient, or an
additional category is desired, a custom category can be created and
used. In order to create a category, a new category symbol should be
added to =gpr-ts-mode-case-formatting= along with the corresponding
formatter and optional dictionary properties. Additionally, an
implementation of =gpr-ts-mode-case-category-p= should be created,
specializing on the new category symbol name. Refer to existing
instances of this predicate function to understand how current
category functions are implemented.

* Troubleshooting

** Org Mode Source Code Blocks
Expand Down Expand Up @@ -379,7 +429,9 @@ package in its absence.
:init
;; Configure source blocks for Org Mode.
(with-eval-after-load 'org-src
(add-to-list 'org-src-lang-modes '("gpr" . gpr-ts)))))
(add-to-list 'org-src-lang-modes '("gpr" . gpr-ts)))
;; Enable auto-casing
:hook (gpr-ts-mode . gpr-ts-auto-case-mode)))

;; Configure Imenu

Expand All @@ -397,6 +449,12 @@ package in its absence.
- Extended example configuration:
- [[https://github.com/brownts/dotemacs-ada][dotemacs-ada]]: Emacs configuration for Ada & GNAT Project

* Command Index
:PROPERTIES:
:APPENDIX: t
:INDEX: fn
:END:

* Keystroke Index
:PROPERTIES:
:APPENDIX: t
Expand Down
72 changes: 69 additions & 3 deletions doc/gpr-ts-mode.texi
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ methods (e.g., regular expressions).

This major mode provides support for syntax highlighting, indentation,
navigation, Imenu, ``which function'' (i.e., displaying the current
function name in the mode line) and outlining (via
@samp{outline-minor-mode}).
function name in the mode line), outlining (via @samp{outline-minor-mode})
and casing.

@strong{Note}: This major mode is based on the Emacs 29 (or newer) built-in
tree-sitter support, not to be confused with the separate Emacs
Expand All @@ -51,9 +51,11 @@ required for @samp{outline-minor-mode} to work with @samp{gpr-ts-mode}.
* Indentation::
* Navigation::
* Imenu::
* Casing::
* Troubleshooting::
* Example Configuration::
* Resources::
* Command Index::
* Keystroke Index::
* Variable Index::
Expand Down Expand Up @@ -416,6 +418,63 @@ order to create a category, a new category symbol should be added to
category symbol name. Refer to existing instances of this function to
understand how current category index functions are implemented.

@node Casing
@chapter Casing

Functionality is provided to manage casing within a GNAT Project
buffer. This includes a number of commands to apply casing rules to
point, to a region or to the entire buffer. The commands can be used
interactively, but may also be useful in other ways (such as calling
the buffer casing command from the @samp{buffer-save-hook}). An auto-casing
minor mode is also provided which performs case formatting as you
type.

@defopt gpr-ts-mode-case-formatting
A set of casing rules, used by the casing commands and modes, which
apply category specific formatting and dictionaries.
@end defopt

@deffn Command gpr-ts-auto-case-mode
A minor mode which applies casing corrections as you type at each
word or subword boundary.
@end deffn

@deffn Command gpr-ts-mode-case-format-region
Applies formatting to the specified region for all items in the
region which match the case formatting categories specified in
@samp{gpr-ts-mode-case-formatting}. When the region doesn't start or stop
exactly on a category boundary, the range is expanded to the
category boundary.
@end deffn

@deffn Command gpr-ts-mode-case-format-at-point
Applies formatting to point, assuming the item at point matches a
case formatting category specified in @samp{gpr-ts-mode-case-formatting}.
When no category is matched, no formatting is applied.
@end deffn

@deffn Command gpr-ts-mode-case-format-buffer
Applies formatting to the entire buffer for all items in the buffer
which match the case formatting categories specified in
@samp{gpr-ts-mode-case-formatting}.
@end deffn

@deffn Command gpr-ts-mode-case-format-dwim
A convenience command which will select between ``region'' and ``at
point'' formatting depending on whether a region is active in the
buffer.
@end deffn

If none of the existing casing categories are sufficient, or an
additional category is desired, a custom category can be created and
used. In order to create a category, a new category symbol should be
added to @samp{gpr-ts-mode-case-formatting} along with the corresponding
formatter and optional dictionary properties. Additionally, an
implementation of @samp{gpr-ts-mode-case-category-p} should be created,
specializing on the new category symbol name. Refer to existing
instances of this predicate function to understand how current
category functions are implemented.

@node Troubleshooting
@chapter Troubleshooting

Expand Down Expand Up @@ -484,7 +543,9 @@ package in its absence.
:init
;; Configure source blocks for Org Mode.
(with-eval-after-load 'org-src
(add-to-list 'org-src-lang-modes '("gpr" . gpr-ts)))))
(add-to-list 'org-src-lang-modes '("gpr" . gpr-ts)))
;; Enable auto-casing
:hook (gpr-ts-mode . gpr-ts-auto-case-mode)))
;; Configure Imenu
Expand Down Expand Up @@ -514,6 +575,11 @@ Extended example configuration:
@end itemize
@end itemize

@node Command Index
@appendix Command Index

@printindex fn

@node Keystroke Index
@appendix Keystroke Index

Expand Down
Loading

0 comments on commit 0f8bb4e

Please sign in to comment.