Created
March 7, 2022 10:52
-
-
Save nozma/ad8cf7903731fdbcf63b7ca4dbc5a54b to your computer and use it in GitHub Desktop.
shrtctsパッケージ用ショートカット設定ファイル
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
- Name: Insert Python code chunk | |
Binding: | | |
context <- rstudioapi::getActiveDocumentContext() | |
id <- context$id | |
location <- c(context$selection[[1]]$range$start) | |
text <- "```{python}\n\n```" | |
rstudioapi::insertText(location, text, id) | |
rstudioapi::setCursorPosition(location + c(1, 0)) | |
Interactive: false | |
- Name: Backspace | |
Binding: | | |
context <- rstudioapi::getActiveDocumentContext() | |
id <- context$id | |
location_start <- c(context$selection[[1]]$range$start) | |
location_end <- c(context$selection[[1]]$range$end) | |
## スタート位置の調整 | |
if (!all(location_start == location_end)) { | |
# pass (選択が範囲の場合、範囲内のみを消す) | |
} else if (location_start[2] == 1) { # 行頭である | |
if (location_start[1] > 1) { # 先頭行ではない | |
# 前の行の末尾が開始点(前の行末の改行を消す) | |
location_start = c(location_start[1] - 1, Inf) | |
} | |
} else { | |
# 行の途中であり、範囲選択でなければカーソルの前の1文字を消す | |
location_start = location_start - c(0, 1) | |
} | |
rstudioapi::modifyRange(rstudioapi::document_range(location_start, location_end), "", id) | |
Interactive: false | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment