Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
toshi-ara committed Dec 22, 2023
2 parents 9f2f468 + 41f8e70 commit c8f3eaa
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 43 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Change Log

## 0.1.0 (2023-12-22)
- enables continuous copying (using start/end tags)

## 0.0.1 (2023-10-29)
- Initial release
33 changes: 28 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,64 +18,81 @@
1. 文章を markdown 形式で箇条書きして下さい
+ markdown 形式でなくても使用可能ですが、
エディタの折り畳み機能を使うことができるため便利です
1. 任意の行で `:call copyline#CopyLine()` を実行して下さい
1. (start) タグのある行あるいはそれより前の行にカーソルを置いてから
`:call copyline#CopyLine()` を実行して下さい
+ 任意のキーボード・ショートカットを割り当てると便利です
+ (例)Ctrl-] に設定する場合:
`nnoremap <silent> <C-]> :call copyline#CopyLine()<enter>`
+ そのショートカットキーを押すと動作します
1. 該当する行のうち
1. (start) タグから (end) タグに挟まれた領域で
**箇条書きのための記号や正答を示す記号を除いた部分**
がクリップボードにコピーされます
1. コマンドの実行後は次の行の先頭にカーソルが移動します
が連続的にクリップボードにコピーされます
+ (start) タグあるいは (end) タグが存在していない場合には
コピーされません
1. コマンドの実行後は (end) タグの次の行の先頭にカーソルが移動します

## 使用例

以下の例で、`:call copyline#CopyLine()` を実行すると、
以下の例で、
カーソルを (start) タグ以前の行に設定してから
`:call copyline#CopyLine()` を実行すると、
`問題文``選択肢1``選択肢2` がクリップボードにコピーされます。

### 記号

`+`, `-`, `*` を使用できます。

```
(start)
+ 問題文
+ 選択肢1 ##
+ 選択肢2
+ 選択肢3(後ろの半角スペースは削除されます)
(end)
```

```
(start)
- 問題文
- 選択肢1 ##
- 選択肢2
(end)
```

```
(start)
* 問題文
* 選択肢1 ##
* 選択肢2
(end)
```

### 英数字

英数字にピリオド、片括弧、両括弧(半角文字)を追加しても動作します。

```
(start)
1. 問題文
a. 選択肢1 ##
b. 選択肢2
(end)
```

```
(start)
1) 問題文
a) 選択肢1 ##
b) 選択肢2
(end)
```

```
(start)
(1) 問題文
(a) 選択肢1 ##
(b) 選択肢2
(end)
```

### 正答・誤答の指定
Expand All @@ -92,10 +109,12 @@
+ ``および`×`は機種依存文字を使う場合があるため非推奨です

```
(start)
- 問題文
- 選択肢1 ##
- 選択肢2 ○
- 選択肢3 ×
(end)
```


Expand Down Expand Up @@ -125,5 +144,9 @@ web の入力項目などに順番に貼り付けることが容易にできま

## Release Notes

### 0.1.0
start/endタグを使用することで連続的にクリップボードに
コピーすることを可能にした(cliborの併用が必要)

### 0.0.1
最初のリリース
50 changes: 33 additions & 17 deletions autoload/copyline.vim
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
scriptencoding utf-8

let g:copyline_str_start = "(start)"
let g:copyline_str_end = "(end)"


" remove leading half-width spaces, tabs and bullet point symbols
let s:pat1 = '^[[:blank:]]*\(+\|-\|\*\|(\?[[:alnum:]]\+[.)]\)*[[:blank:]]*'
" remove last half-width spaces, tabs and symbols
Expand All @@ -8,24 +12,36 @@ let s:pat2 = '[[:blank:]]*\(#*\|[○×]\)[[:blank:]]*$'

function! copyline#CopyLine() abort
let pos = getpos(".")
call setpos(".", [0, pos[1], 0, 0])

let text = getline(pos[1])
" get stirings
let text1 = substitute(text, s:pat1, "", "")
let result = substitute(text1, s:pat2, "", "")

" cursor down
" https://sy-base.com/myrobotics/vim/vim-cursor-position/
let pos[1] += 1
let pos[2] = 0
call setpos(".", pos)

" copy result to clipboard
if result != ""
echo "Copied [".result."]"
let @+ = result
else
echo "Not copied."
let flags = "cW"
let startLine = search(g:copyline_str_start, flags)
let endLine = search(g:copyline_str_end, flags)

if startLine == 0 || endLine == 0
echo "missing start or end tag"
call setpos(".", pos)
return
endif

let texts = getline(startLine + 1, endLine - 1)
for text in texts
" get stirings
let text1 = substitute(text, s:pat1, "", "")
let result = substitute(text1, s:pat2, "", "")

" copy result to clipboard
if result != ""
echo "Copied [".result."]"
let @+ = result
sleep 1
else
echo "Not copied."
endif

endfor

" call cursor(endLine + 1, 0)
call setpos(".", [0, endLine + 1, 0, 0])
endfunction

48 changes: 27 additions & 21 deletions doc/sample.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
# 箇条書き(記号)

+ 問題文
+ 選択肢1
+ 選択肢2(後ろの半角スペースおよびタブは削除される)
(start)
+ 問題文1
+ 選択肢1-1
+ 選択肢1-2(後ろの半角スペースおよびタブは削除される)
+  (全角スペースはコピーされる) 
+ 問題文
- 選択肢1
- 選択肢2
+ 問題文
* 選択肢1
* 選択肢2
+ 問題文2
- 選択肢2-1
- 選択肢2-2
+ 問題文3
* 選択肢3-1
* 選択肢3-2
(end)


# 箇条書き(英数字)

1. 問題文
1) 選択肢1
2) 選択肢2
2. 問題文
(1) 選択肢1
(2) 選択肢2
3. 問題文
a) 選択肢1
b) 選択肢2
4. 問題文
(A) 選択肢1
(B) 選択肢2
(start)
1. 問題文1
1) 選択肢1-1
2) 選択肢1-2
2. 問題文2
(1) 選択肢2-1
(2) 選択肢2-2
3. 問題文3
a) 選択肢3-1
b) 選択肢3-2
4. 問題文4
(A) 選択肢4-1
(B) 選択肢4-2
(end)


# 正答および誤答の記号

(start)
+ 正答および誤答を示す記号は削除される
+ 選択肢1 ##
+ 選択肢2 ○
+ 選択肢3 ×
(end)

0 comments on commit c8f3eaa

Please sign in to comment.