Package 'atcursor'

Title: Get the current word or selection at cursor
Description: Get the current word or selection at cursor using the {rstudioapi}. Works in VSCode and RStudio.
Authors: Miles McBain [aut, cre]
Maintainer: Miles McBain <[email protected]>
License: MIT + file LICENSE
Version: 0.0.2
Built: 2024-10-27 02:47:26 UTC
Source: https://github.com/milesmcbain/atcursor

Help Index


get the column the cursor is on from a selection

Description

get the column the cursor is on from a selection

Usage

get_cursor_col(current_selection)

Arguments

current_selection

a selection from the rstudioapi document context


get the line the cursor is on

Description

get the line the cursor is on

Usage

get_cursor_line(
  context,
  current_selection = rstudioapi::primary_selection(context)
)

Arguments

context

the rtsudioapi document context

current_selection

the selection to find the line for, defaults to primary selection


Get word or selection at cursor

Description

Uses the rstudioapi to get the word the cursor is on or active selection in the active document. This is useful for addins that want bind keys to trigger commands using the cursor context.

Usage

get_word_or_selection()

Details

This function defines a word as a possibly namespaced R symbol. So a cursor on the name of pkg::var(foo) will return 'pkg::var'. $ is considered a separator.

If there are any selections the primary selection takes precedence and is returned.

Value

a character vector containing the current word at the cursor or primary selection