Multiple fixes & features: cite_packages, align helpers, header toggler, hotkeys, chunknamer (#20, #29, #57, #58, #59, #60, #67, #70, #73)#74
Open
VincentGuyader wants to merge 9 commits into
Conversation
- align_tilde()/align_pipe() addins and their pure helpers align_text() / align_pipe_text() (#58, #67). - default_hotkeys() returns the default shortcut map; rewrites Cmd to Ctrl on non-macOS platforms (#70). Adds align_* and br entries (#29). - br_r() addin inserts <br> (#60). - headr_toggler() addin + toggle_header() pure helper cycle H1..H6..plain (#59).
The previous regex relied on a lookbehind, then matched the outer
literal (whitespace + optional quote + name) but kept the lookbehind's
right-hand side in the match. So library("dplyr") yielded '"dplyr',
which never matched utils::citation() and showed up as a duplicate of
'dplyr' in the output.
Switch to a capture-group extraction (regmatches_group helper) so the
returned name is exactly the package identifier. Also tighten the
regex to require a leading letter, matching valid R package names.
…lcomment The Cmd->Ctrl rewrite used on non-macOS turned chunk's 'Ctrl+Alt+Cmd+C' into 'Ctrl+Alt+C', which collides with htmlcomment's existing 'Ctrl+Alt+C'. Move chunk to a Shift-bearing chord that survives the rewrite as a unique combo, and assert at runtime that the produced map has no duplicates so future additions catch their own collisions.
The previous commit advertised align_text() as a 'shared pure helper' but the addins continued to use the legacy find_regex/assemble_insert chain; align_text() was exported and only exercised by tests. Introduce an internal align_addin(find, fixed) that captures the selection rows, runs align_text(), and writes the result back via a single rstudioapi::modifyRange call. align_arrow / align_equal / align_tilde are now one-line wrappers around it, so the same code path runs in tests and in RStudio.
The previous formula (nchar(N) - 1, floored at 2) under-sized the zero-padding once the document had 100+ unnamed chunks: 'remedy01, remedy02, ..., remedy99, remedy100' with mismatched widths broke lexical ordering. Drop the -1 so width tracks length(no_name) exactly.
…-review)
knitr accepts both ```{r} and ```{R}. The regex used to anchor on
lowercase r only, so any R chunk in the source was left unnamed
forever. Make all three regex spots case-insensitive to [rR] and add
a regression test.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactored the addins around pure helpers so the suite can run headless (28 new assertions in CI without an RStudio session).
Bug fixes
stanblock when adding names #57): tighten the chunk-header regex (^\\\\`\`\{r(\\s|,|\})) sostan/python/sql/bash` chunks are no longer renamed.rename_chunks()and fixed counter width —>= 100unnamed chunks now zero-pad to 3 digits, restoring lexical = numeric order.library("dplyr")yieldsdplyr(was previously"dplyrwith the leading quote, which brokeutils::citation()).Cmd → Ctrlrewrite on non-macOS was collapsingchunk = Ctrl+Alt+Cmd+CintoCtrl+Alt+C, colliding withhtmlcomment. Movedchunkto a Shift-bearing combo and added a runtime collision check that fails fast if any future addition reintroduces a duplicate.align_text()via internalalign_addin()(the previous commit advertised the helper as “mutualisé” but the addins still used the legacy chain).Features
cite_packages()andpackages_in_text()exported. Picks uplibrary,require,requireNamespaceandpkg::funreferences.align_pipe_text()for markdown table cell padding.toggle_header()(cycle plain → H1 → … → H6 → plain).<br>at cursor.align#29, the package should detect if the user is in mac or windows to set default keyshort cuts considering that #70):align_*andbradded to the default map;default_hotkeys(os = …)rewritesCmdtoCtrlon non-Darwin.NAname disables auto-naming entirely (rename_chunks()becomes a no-op).Pure helpers (new exports)
rename_chunks(),align_text(),align_pipe_text(),toggle_header(),default_hotkeys(),packages_in_text(),cite_packages().Note on CI
The repo has no
R-CMD-checkworkflow. I prepared a standard r-lib/actions v2 file but pushing it requiresworkflowscope on the PAT. Refresh withgh auth refresh -s workflowand I can add it; otherwise drop in a.github/workflows/R-CMD-check.yamlfrom the r-lib/actions standard template.Test plan
testthat::test_local()(no RStudio): 0 FAIL / 26 SKIP (RStudio-only) / 54 PASS.R CMD check: 0 ERROR / 2 WARNINGs (pre-existing — vignetteinst/docmissing).Closes #20
Closes #29
Closes #57
Closes #58
Closes #59
Closes #60
Closes #67
Closes #70
Closes #73