pub struct Config {Show 26 fields
pub line_width: usize,
pub tab_size: usize,
pub use_tabchars: bool,
pub max_empty_lines: usize,
pub max_lines_hwrap: usize,
pub max_pargs_hwrap: usize,
pub max_subgroups_hwrap: usize,
pub dangle_parens: bool,
pub dangle_align: DangleAlign,
pub min_prefix_chars: usize,
pub max_prefix_chars: usize,
pub separate_ctrl_name_with_space: bool,
pub separate_fn_name_with_space: bool,
pub command_case: CaseStyle,
pub keyword_case: CaseStyle,
pub enable_markup: bool,
pub reflow_comments: bool,
pub first_comment_is_literal: bool,
pub literal_comment_pattern: String,
pub bullet_char: String,
pub enum_char: String,
pub fence_pattern: String,
pub ruler_pattern: String,
pub hashruler_min_length: usize,
pub canonicalize_hashrulers: bool,
pub per_command_overrides: HashMap<String, PerCommandConfig>,
}Expand description
Full formatter configuration.
Construct Config::default and set fields as needed before passing it to
format_source or related functions.
use cmakefmt::{Config, CaseStyle, DangleAlign};
let config = Config {
line_width: 100,
command_case: CaseStyle::Lower,
dangle_parens: true,
dangle_align: DangleAlign::Open,
..Config::default()
};§Defaults
| Field | Default |
|---|---|
line_width | 80 |
tab_size | 2 |
use_tabchars | false |
max_empty_lines | 1 |
command_case | CaseStyle::Lower |
keyword_case | CaseStyle::Upper |
dangle_parens | false |
dangle_align | DangleAlign::Prefix |
enable_markup | true |
reflow_comments | false |
first_comment_is_literal | true |
Fields§
§line_width: usizeMaximum rendered line width before wrapping is attempted.
tab_size: usizeNumber of spaces that make up one indentation level when
Self::use_tabchars is false.
use_tabchars: boolEmit tab characters for indentation instead of spaces.
max_empty_lines: usizeMaximum number of consecutive empty lines to preserve.
max_lines_hwrap: usizeMaximum number of wrapped lines tolerated before switching to a more vertical layout.
max_pargs_hwrap: usizeMaximum number of positional arguments to keep in a hanging-wrap layout before going vertical.
max_subgroups_hwrap: usizeMaximum number of keyword/flag subgroups to keep in a horizontal wrap.
dangle_parens: boolPlace the closing ) on its own line when a call wraps.
dangle_align: DangleAlignAlignment strategy for a dangling closing ).
min_prefix_chars: usizeLower bound used by layout heuristics when deciding whether a command name is short enough to prefer one style over another.
max_prefix_chars: usizeUpper bound used by layout heuristics when deciding whether a command name is long enough to prefer one style over another.
separate_ctrl_name_with_space: boolInsert a space before ( for control-flow commands such as if.
separate_fn_name_with_space: boolInsert a space before ( for function/macro definitions.
command_case: CaseStyleOutput casing policy for command names.
keyword_case: CaseStyleOutput casing policy for recognized keywords and flags.
enable_markup: boolEnable markup-aware comment handling.
reflow_comments: boolReflow plain line comments to fit within the configured width.
first_comment_is_literal: boolPreserve the first comment block in a file literally.
literal_comment_pattern: StringRegex for comments that should never be reflowed.
bullet_char: StringPreferred bullet character when normalizing list markup.
enum_char: StringPreferred enumeration punctuation when normalizing numbered list markup.
fence_pattern: StringRegex describing fenced literal comment blocks.
ruler_pattern: StringRegex describing ruler-style comments.
hashruler_min_length: usizeMinimum ruler length before a #----- style line is treated as a ruler.
canonicalize_hashrulers: boolNormalize ruler comments when markup handling is enabled.
per_command_overrides: HashMap<String, PerCommandConfig>Per-command configuration overrides keyed by lowercase command name.
Implementations§
Source§impl Config
impl Config
Sourcepub fn for_file(file_path: &Path) -> Result<Self>
pub fn for_file(file_path: &Path) -> Result<Self>
Load configuration for a file at the given path.
Searches for the nearest supported user config (.cmakefmt.yaml,
.cmakefmt.yml, then .cmakefmt.toml) starting from the file’s
directory and walking up to the repository/filesystem root. If none is
found, falls back to the same filenames in the home directory.
Sourcepub fn from_file(path: &Path) -> Result<Self>
pub fn from_file(path: &Path) -> Result<Self>
Load configuration from a specific supported config file.
Sourcepub fn from_files(paths: &[PathBuf]) -> Result<Self>
pub fn from_files(paths: &[PathBuf]) -> Result<Self>
Load configuration by merging several supported config files in order.
Later files override earlier files.
Sourcepub fn config_sources_for(file_path: &Path) -> Vec<PathBuf>
pub fn config_sources_for(file_path: &Path) -> Vec<PathBuf>
Return the config files that would be applied for the given file.
When config discovery is used, this is either the nearest supported config file found by walking upward from the file, or a home directory config if no nearer config exists.
Source§impl Config
impl Config
Sourcepub fn for_command(&self, command_name: &str) -> CommandConfig<'_>
pub fn for_command(&self, command_name: &str) -> CommandConfig<'_>
Returns a Config with any per-command overrides applied for the
given command name, plus the appropriate space-before-paren setting.
Sourcepub fn apply_command_case(&self, name: &str) -> String
pub fn apply_command_case(&self, name: &str) -> String
Apply the command_case rule to a command name.
Sourcepub fn apply_keyword_case(&self, keyword: &str) -> String
pub fn apply_keyword_case(&self, keyword: &str) -> String
Apply the keyword_case rule to a keyword token.
Sourcepub fn indent_str(&self) -> String
pub fn indent_str(&self) -> String
The indentation string (spaces or tab).
Trait Implementations§
impl Eq for Config
impl StructuralPartialEq for Config
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.