-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
919cfae
commit 239e98c
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
;;; Directory Local Variables -*- no-byte-compile: t -*- | ||
;;; For more information see (info "(emacs) Directory Variables") | ||
|
||
((c++-mode . ((c-file-style . "filament") | ||
(apheleia-inhibit . t))) | ||
(c-mode . ((c-file-style . "filament") | ||
(apheleia-inhibit . t)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
;;; c-filament-style.el --- Filament C++ style -*- lexical-binding: t -*- | ||
|
||
;; Copyright (C) 2023 Google LLC | ||
|
||
;; Author: Eliza Velasquez | ||
;; Version: 0.1.0 | ||
;; Created: 2023-10-31 | ||
;; Package-Requires: ((emacs "24.1")) | ||
;; Keywords: c | ||
;; URL: https://github.com/google/filament | ||
;; SPDX-License-Identifier: Apache-2 | ||
|
||
;;; Commentary: | ||
|
||
;; Defines a basic Filament style for C++ code in Emacs. | ||
|
||
;;; Code: | ||
|
||
(require 'cc-mode) | ||
(defvar c-syntactic-context) | ||
|
||
(defun c-filament-style-lineup-brace-list-intro (langelem) | ||
"Indent first line of braced lists in the Filament style. | ||
This properly indents doubled-up arglists + lists, e.g. ({. It | ||
also properly indents enums at 1x and other lists at 2x. | ||
LANGELEM is the cons of the syntactic symbol and the anchor | ||
position (or nil if there is none)." | ||
(save-excursion | ||
(let (case-fold-search) | ||
(goto-char (c-langelem-pos langelem)) | ||
(if (looking-at "enum\\b") | ||
c-basic-offset | ||
(if (assq 'arglist-cont-nonempty c-syntactic-context) | ||
(- c-basic-offset) | ||
(* 2 c-basic-offset)))))) | ||
|
||
(defun c-filament-style-lineup-brace-list-entry (_langelem) | ||
"Indent following lines in braced lists in the Filament style. | ||
This properly indents doubled-up arglists + lists, e.g. ({." | ||
(if (assq 'arglist-cont-nonempty c-syntactic-context) | ||
(- (* c-basic-offset 2)) | ||
0)) | ||
|
||
(defun c-filament-style-lineup-arglist (langelem) | ||
"Indent following lines in braced lists in the Filament style. | ||
This properly indents arglists nested in if statements. LANGELEM | ||
is the cons of the syntactic symbol and the anchor position (or | ||
nil if there is none)." | ||
(save-excursion | ||
(let (case-fold-search) | ||
(goto-char (c-langelem-pos langelem)) | ||
(if (and (cdr c-syntactic-context) | ||
(looking-at "if\\b")) | ||
c-basic-offset | ||
(* 2 c-basic-offset))))) | ||
|
||
(c-add-style "filament" | ||
'((c-basic-offset . 4) | ||
(c-offsets-alist | ||
(innamespace . 0) | ||
(inextern-lang . 0) | ||
(arglist-intro . c-filament-style-lineup-arglist) | ||
(arglist-cont . 0) | ||
(arglist-cont-nonempty . c-filament-style-lineup-arglist) | ||
(arglist-close . c-filament-style-lineup-arglist) | ||
(statement-cont . ++) | ||
(case-label . +) | ||
(brace-list-intro . c-filament-style-lineup-brace-list-intro) | ||
(brace-list-entry . c-filament-style-lineup-brace-list-entry) | ||
(brace-list-close . c-filament-style-lineup-brace-list-entry) | ||
(label . [0])))) | ||
|
||
(provide 'c-filament-style) | ||
|
||
;;; c-filament-style.el ends here |