R/bookmarks.R

Defines functions bookmark_check go_to_bookmark_09 bookmark_09 go_to_bookmark_08 bookmark_08 go_to_bookmark_07 bookmark_07 go_to_bookmark_06 bookmark_06 go_to_bookmark_05 bookmark_05 go_to_bookmark_04 bookmark_04 go_to_bookmark_03 bookmark_03 go_to_bookmark_02 bookmark_02 go_to_bookmark_01 bookmark_01

# Alt+Shift+m, Ctrl+1 (keypad)
bookmark_01 <- function(){
  if (exists("bookmark_01_context")){
    default <- bookmark_01_context$memo_unicode
    indication <- "Modified"
  } else {
    default <- "Bookmark 01: "
    indication <- "Created"
  }
  bookmark_01_context <- rstudioapi::getSourceEditorContext() # 먼저 작업 중인 script 파일에서, 정보를 저장.
  input <- stringi::stri_escape_unicode(svDialogs::dlgInput("Title of the Bookmark 01?: ",
                                                            default=default)$res)
  if (length(input)){
    # Encoding(input) <- "UTF-8"
    bookmark_01_context$memo_unicode <- input
    bookmark_01_context$memo <- stringi::stri_unescape_unicode(input)
  } else {
    bookmark_01_context$memo <- "Bookmark 01: "
  }
  bookmark_01_context$ts <- Sys.time()
  assign("bookmark_01_context", bookmark_01_context, envir = parent.frame()) # 서로 독립적인 함수에서, 먼저 생성된 변수를 사용하기 위해 envir 옵션을 사용.
  cat(paste(rep("=", 60), collapse =""), "\n")
  cat(paste0(crayon::bgBlue(indication), " ", bookmark_01_context$memo))
  cat(paste0("\n", bookmark_01_context$ts, "\n"))
}

# Alt+Shift+b, Ctrl+1 (keypad)
go_to_bookmark_01 <- function(){
  if ("bookmark_01_context" %in% ls(pattern="bookmark_0", envir = parent.frame())){
    CurrentSourceEditor <- rstudioapi::getSourceEditorContext() # 돌아가기 전 작업하던 script의 정보를 저장.

    if (identical(bookmark_01_context$path, CurrentSourceEditor$path)){
    } else {
      rstudioapi::navigateToFile(file=bookmark_01_context$path,
                                 line = bookmark_01_context$selection[[1]]$range$end[1])
    }

    myposition <- bookmark_01_context$selection[[1]]$range$end

    # 혹시라도 이동한 문서의 위치에서 작업을 하여, 이전의 위치를 나타내는 line number에 변화가 있을 수도 있는 것을 반영.
    if (CurrentSourceEditor$selection[[1]]$range$end[1] < bookmark_01_context$selection[[1]]$range$end[1]){
      line_number <- bookmark_01_context$selection[[1]]$range$end[1] + (length(CurrentSourceEditor$contents) - length(bookmark_01_context$contents))
      myposition <- rstudioapi::document_position(line_number, bookmark_01_context$selection[[1]]$range$end[2])
    }

    rstudioapi::setCursorPosition(position=myposition, # 위에서 저장한 정보를 이용하여, 커서 위치를 이전 작업하던 명령줄의 마지막 칸에 위치 시킴.
                                  id=CurrentSourceEditor$id)
    cat(paste(rep("=", 60), collapse =""), "\n")
    cat(paste0(crayon::bgCyan("Go to"), " ", bookmark_01_context$memo))
    cat(paste0("\n", bookmark_01_context$ts, "\n"))
  } else {
    cat("Warning!: There is no object bookmark_01_context")
  }
}

# Alt+Shift+m, Ctrl+2 (keypad)
bookmark_02 <- function(){
  if (exists("bookmark_02_context")){
    default <- bookmark_02_context$memo
    indication <- "Modified"
  } else {
    default <- "Bookmark 02: "
    indication <- "Created"
  }
  bookmark_02_context <- rstudioapi::getSourceEditorContext() # 먼저 작업 중인 script 파일에서, 정보를 저장.
  input <- svDialogs::dlgInput("Title of the Bookmark 02?: ", default=default)$res
  if (length(input)){
    Encoding(input) <- "UTF-8"
    bookmark_02_context$memo <- input
  } else {
    bookmark_02_context$memo <- "Bookmark 02: "
  }
  bookmark_02_context$ts <- Sys.time()
  assign("bookmark_02_context", bookmark_02_context, envir = parent.frame()) # 서로 독립적인 함수에서, 먼저 생성된 변수를 사용하기 위해 envir 옵션을 사용.
  cat(paste(rep("=", 60), collapse =""), "\n")
  cat(paste0(crayon::bgBlue(indication), " ", bookmark_02_context$memo))
  cat(paste0("\n", bookmark_02_context$ts, "\n"))
}

# Alt+Shift+b, Ctrl+2 (keypad)
go_to_bookmark_02 <- function(){
  if ("bookmark_02_context" %in% ls(pattern="bookmark_0", envir = parent.frame())){
    CurrentSourceEditor <- rstudioapi::getSourceEditorContext() # 돌아가기 전 작업하던 script의 정보를 저장.

    if (identical(bookmark_02_context$path, CurrentSourceEditor$path)){
    } else {
      rstudioapi::navigateToFile(file=bookmark_02_context$path,
                                 line = bookmark_02_context$selection[[1]]$range$end[1])
    }

    myposition <- bookmark_02_context$selection[[1]]$range$end

    # 혹시라도 이동한 문서의 위치에서 작업을 하여, 이전의 위치를 나타내는 line number에 변화가 있을 수도 있는 것을 반영.
    if (CurrentSourceEditor$selection[[1]]$range$end[1] < bookmark_02_context$selection[[1]]$range$end[1]){
      line_number <- bookmark_02_context$selection[[1]]$range$end[1] + (length(CurrentSourceEditor$contents) - length(bookmark_02_context$contents))
      myposition <- rstudioapi::document_position(line_number, bookmark_02_context$selection[[1]]$range$end[2])
    }

    rstudioapi::setCursorPosition(position=myposition, # 위에서 저장한 정보를 이용하여, 커서 위치를 이전 작업하던 명령줄의 마지막 칸에 위치 시킴.
                                  id=CurrentSourceEditor$id)
    cat(paste(rep("=", 60), collapse =""), "\n")
    cat(paste0(crayon::bgCyan("Go to"), " ", bookmark_02_context$memo))
    cat(paste0("\n", bookmark_02_context$ts, "\n"))
  } else {
    cat("Warning!: There is no object bookmark_02_context")
  }
}

# Alt+Shift+m, Ctrl+3 (keypad)
bookmark_03 <- function(){
  if (exists("bookmark_03_context")){
    default <- bookmark_03_context$memo
    indication <- "Modified"
  } else {
    default <- "Bookmark 03: "
    indication <- "Created"
  }
  bookmark_03_context <- rstudioapi::getSourceEditorContext() # 먼저 작업 중인 script 파일에서, 정보를 저장.
  input <- svDialogs::dlgInput("Title of the Bookmark 03?: ", default=default)$res
  if (length(input)){
    Encoding(input) <- "UTF-8"
    bookmark_03_context$memo <- input
  } else {
    bookmark_03_context$memo <- "Bookmark 03: "
  }
  bookmark_03_context$ts <- Sys.time()
  assign("bookmark_03_context", bookmark_03_context, envir = parent.frame()) # 서로 독립적인 함수에서, 먼저 생성된 변수를 사용하기 위해 envir 옵션을 사용.
  cat(paste(rep("=", 60), collapse =""), "\n")
  cat(paste0(crayon::bgBlue(indication), " ", bookmark_03_context$memo))
  cat(paste0("\n", bookmark_03_context$ts, "\n"))
}

# Alt+Shift+b, Ctrl+3 (keypad)
go_to_bookmark_03 <- function(){
  if ("bookmark_03_context" %in% ls(pattern="bookmark_0", envir = parent.frame())){
    CurrentSourceEditor <- rstudioapi::getSourceEditorContext() # 돌아가기 전 작업하던 script의 정보를 저장.

    if (identical(bookmark_03_context$path, CurrentSourceEditor$path)){
    } else {
      rstudioapi::navigateToFile(file=bookmark_03_context$path,
                                 line = bookmark_03_context$selection[[1]]$range$end[1])
    }

    myposition <- bookmark_03_context$selection[[1]]$range$end

    # 혹시라도 이동한 문서의 위치에서 작업을 하여, 이전의 위치를 나타내는 line number에 변화가 있을 수도 있는 것을 반영.
    if (CurrentSourceEditor$selection[[1]]$range$end[1] < bookmark_03_context$selection[[1]]$range$end[1]){
      line_number <- bookmark_03_context$selection[[1]]$range$end[1] + (length(CurrentSourceEditor$contents) - length(bookmark_03_context$contents))
      myposition <- rstudioapi::document_position(line_number, bookmark_03_context$selection[[1]]$range$end[2])
    }

    rstudioapi::setCursorPosition(position=myposition, # 위에서 저장한 정보를 이용하여, 커서 위치를 이전 작업하던 명령줄의 마지막 칸에 위치 시킴.
                                  id=CurrentSourceEditor$id)
    cat(paste(rep("=", 60), collapse =""), "\n")
    cat(paste0(crayon::bgCyan("Go to"), " ", bookmark_03_context$memo))
    cat(paste0("\n", bookmark_03_context$ts, "\n"))
  } else {
    cat("Warning!: There is no object bookmark_03_context")
  }
}

# Alt+Shift+m, Ctrl+4 (keypad)
bookmark_04 <- function(){
  if (exists("bookmark_04_context")){
    default <- bookmark_04_context$memo
    indication <- "Modified"
  } else {
    default <- "Bookmark 04: "
    indication <- "Created"
  }
  bookmark_04_context <- rstudioapi::getSourceEditorContext() # 먼저 작업 중인 script 파일에서, 정보를 저장.
  input <- svDialogs::dlgInput("Title of the Bookmark 04?: ", default=default)$res
  if (length(input)){
    Encoding(input) <- "UTF-8"
    bookmark_04_context$memo <- input
  } else {
    bookmark_04_context$memo <- "Bookmark 04: "
  }
  bookmark_04_context$ts <- Sys.time()
  assign("bookmark_04_context", bookmark_04_context, envir = parent.frame()) # 서로 독립적인 함수에서, 먼저 생성된 변수를 사용하기 위해 envir 옵션을 사용.
  cat(paste(rep("=", 60), collapse =""), "\n")
  cat(paste0(crayon::bgBlue(indication), " ", bookmark_04_context$memo))
  cat(paste0("\n", bookmark_04_context$ts, "\n"))
}

# Alt+Shift+b, Ctrl+4 (keypad)
go_to_bookmark_04 <- function(){
  if ("bookmark_04_context" %in% ls(pattern="bookmark_0", envir = parent.frame())){
    CurrentSourceEditor <- rstudioapi::getSourceEditorContext() # 돌아가기 전 작업하던 script의 정보를 저장.

    if (identical(bookmark_04_context$path, CurrentSourceEditor$path)){
    } else {
      rstudioapi::navigateToFile(file=bookmark_04_context$path,
                                 line = bookmark_04_context$selection[[1]]$range$end[1])
    }

    myposition <- bookmark_04_context$selection[[1]]$range$end

    # 혹시라도 이동한 문서의 위치에서 작업을 하여, 이전의 위치를 나타내는 line number에 변화가 있을 수도 있는 것을 반영.
    if (CurrentSourceEditor$selection[[1]]$range$end[1] < bookmark_04_context$selection[[1]]$range$end[1]){
      line_number <- bookmark_04_context$selection[[1]]$range$end[1] + (length(CurrentSourceEditor$contents) - length(bookmark_04_context$contents))
      myposition <- rstudioapi::document_position(line_number, bookmark_04_context$selection[[1]]$range$end[2])
    }

    rstudioapi::setCursorPosition(position=myposition, # 위에서 저장한 정보를 이용하여, 커서 위치를 이전 작업하던 명령줄의 마지막 칸에 위치 시킴.
                                  id=CurrentSourceEditor$id)
    cat(paste(rep("=", 60), collapse =""), "\n")
    cat(paste0(crayon::bgCyan("Go to"), " ", bookmark_04_context$memo))
    cat(paste0("\n", bookmark_04_context$ts, "\n"))
  } else {
    cat("Warning!: There is no object bookmark_04_context")
  }
}

# Alt+Shift+m, Ctrl+5 (keypad)
bookmark_05 <- function(){
  if (exists("bookmark_05_context")){
    default <- bookmark_05_context$memo
    indication <- "Modified"
  } else {
    default <- "Bookmark 05: "
    indication <- "Created"
  }
  bookmark_05_context <- rstudioapi::getSourceEditorContext() # 먼저 작업 중인 script 파일에서, 정보를 저장.
  input <- svDialogs::dlgInput("Title of the Bookmark 05?: ", default=default)$res
  if (length(input)){
    Encoding(input) <- "UTF-8"
    bookmark_05_context$memo <- input
  } else {
    bookmark_05_context$memo <- "Bookmark 05: "
  }
  bookmark_05_context$ts <- Sys.time()
  assign("bookmark_05_context", bookmark_05_context, envir = parent.frame()) # 서로 독립적인 함수에서, 먼저 생성된 변수를 사용하기 위해 envir 옵션을 사용.
  cat(paste(rep("=", 60), collapse =""), "\n")
  cat(paste0(crayon::bgBlue(indication), " ", bookmark_05_context$memo))
  cat(paste0("\n", bookmark_05_context$ts, "\n"))
}

# Alt+Shift+b, Ctrl+5 (keypad)
go_to_bookmark_05 <- function(){
  if ("bookmark_05_context" %in% ls(pattern="bookmark_0", envir = parent.frame())){
    CurrentSourceEditor <- rstudioapi::getSourceEditorContext() # 돌아가기 전 작업하던 script의 정보를 저장.

    if (identical(bookmark_05_context$path, CurrentSourceEditor$path)){
    } else {
      rstudioapi::navigateToFile(file=bookmark_05_context$path,
                                 line = bookmark_05_context$selection[[1]]$range$end[1])
    }

    myposition <- bookmark_05_context$selection[[1]]$range$end

    # 혹시라도 이동한 문서의 위치에서 작업을 하여, 이전의 위치를 나타내는 line number에 변화가 있을 수도 있는 것을 반영.
    if (CurrentSourceEditor$selection[[1]]$range$end[1] < bookmark_05_context$selection[[1]]$range$end[1]){
      line_number <- bookmark_05_context$selection[[1]]$range$end[1] + (length(CurrentSourceEditor$contents) - length(bookmark_05_context$contents))
      myposition <- rstudioapi::document_position(line_number, bookmark_05_context$selection[[1]]$range$end[2])
    }

    rstudioapi::setCursorPosition(position=myposition, # 위에서 저장한 정보를 이용하여, 커서 위치를 이전 작업하던 명령줄의 마지막 칸에 위치 시킴.
                                  id=CurrentSourceEditor$id)
    cat(paste(rep("=", 60), collapse =""), "\n")
    cat(paste0(crayon::bgCyan("Go to"), " ", bookmark_05_context$memo))
    cat(paste0("\n", bookmark_05_context$ts, "\n"))
  } else {
    cat("Warning!: There is no object bookmark_05_context")
  }
}

# Alt+Shift+m, Ctrl+6 (keypad)
bookmark_06 <- function(){
  if (exists("bookmark_06_context")){
    default <- bookmark_06_context$memo
    indication <- "Modified"
  } else {
    default <- "Bookmark 06: "
    indication <- "Created"
  }
  bookmark_06_context <- rstudioapi::getSourceEditorContext() # 먼저 작업 중인 script 파일에서, 정보를 저장.
  input <- svDialogs::dlgInput("Title of the Bookmark 06?: ", default=default)$res
  if (length(input)){
    Encoding(input) <- "UTF-8"
    bookmark_06_context$memo <- input
  } else {
    bookmark_06_context$memo <- "Bookmark 06: "
  }
  bookmark_06_context$ts <- Sys.time()
  assign("bookmark_06_context", bookmark_06_context, envir = parent.frame()) # 서로 독립적인 함수에서, 먼저 생성된 변수를 사용하기 위해 envir 옵션을 사용.
  cat(paste(rep("=", 60), collapse =""), "\n")
  cat(paste0(crayon::bgBlue(indication), " ", bookmark_06_context$memo))
  cat(paste0("\n", bookmark_06_context$ts, "\n"))
}

# Alt+Shift+b, Ctrl+6 (keypad)
go_to_bookmark_06 <- function(){
  if ("bookmark_06_context" %in% ls(pattern="bookmark_0", envir = parent.frame())){
    CurrentSourceEditor <- rstudioapi::getSourceEditorContext() # 돌아가기 전 작업하던 script의 정보를 저장.

    if (identical(bookmark_06_context$path, CurrentSourceEditor$path)){
    } else {
      rstudioapi::navigateToFile(file=bookmark_06_context$path,
                                 line = bookmark_06_context$selection[[1]]$range$end[1])
    }

    myposition <- bookmark_06_context$selection[[1]]$range$end

    # 혹시라도 이동한 문서의 위치에서 작업을 하여, 이전의 위치를 나타내는 line number에 변화가 있을 수도 있는 것을 반영.
    if (CurrentSourceEditor$selection[[1]]$range$end[1] < bookmark_06_context$selection[[1]]$range$end[1]){
      line_number <- bookmark_06_context$selection[[1]]$range$end[1] + (length(CurrentSourceEditor$contents) - length(bookmark_06_context$contents))
      myposition <- rstudioapi::document_position(line_number, bookmark_06_context$selection[[1]]$range$end[2])
    }

    rstudioapi::setCursorPosition(position=myposition, # 위에서 저장한 정보를 이용하여, 커서 위치를 이전 작업하던 명령줄의 마지막 칸에 위치 시킴.
                                  id=CurrentSourceEditor$id)
    cat(paste(rep("=", 60), collapse =""), "\n")
    cat(paste0(crayon::bgCyan("Go to"), " ", bookmark_06_context$memo))
    cat(paste0("\n", bookmark_06_context$ts, "\n"))
  } else {
    cat("Warning!: There is no object bookmark_06_context")
  }
}

# Alt+Shift+m, Ctrl+7 (keypad)
bookmark_07 <- function(){
  if (exists("bookmark_07_context")){
    default <- bookmark_07_context$memo
    indication <- "Modified"
  } else {
    default <- "Bookmark 07: "
    indication <- "Created"
  }
  bookmark_07_context <- rstudioapi::getSourceEditorContext() # 먼저 작업 중인 script 파일에서, 정보를 저장.
  input <- svDialogs::dlgInput("Title of the Bookmark 07?: ", default=default)$res
  if (length(input)){
    Encoding(input) <- "UTF-8"
    bookmark_07_context$memo <- input
  } else {
    bookmark_07_context$memo <- "Bookmark 07: "
  }
  bookmark_07_context$ts <- Sys.time()
  assign("bookmark_07_context", bookmark_07_context, envir = parent.frame()) # 서로 독립적인 함수에서, 먼저 생성된 변수를 사용하기 위해 envir 옵션을 사용.
  cat(paste(rep("=", 60), collapse =""), "\n")
  cat(paste0(crayon::bgBlue(indication), " ", bookmark_07_context$memo))
  cat(paste0("\n", bookmark_07_context$ts, "\n"))
}

# Alt+Shift+b, Ctrl+7 (keypad)
go_to_bookmark_07 <- function(){
  if ("bookmark_07_context" %in% ls(pattern="bookmark_0", envir = parent.frame())){
    CurrentSourceEditor <- rstudioapi::getSourceEditorContext() # 돌아가기 전 작업하던 script의 정보를 저장.

    if (identical(bookmark_07_context$path, CurrentSourceEditor$path)){
    } else {
      rstudioapi::navigateToFile(file=bookmark_07_context$path,
                                 line = bookmark_07_context$selection[[1]]$range$end[1])
    }

    myposition <- bookmark_07_context$selection[[1]]$range$end

    # 혹시라도 이동한 문서의 위치에서 작업을 하여, 이전의 위치를 나타내는 line number에 변화가 있을 수도 있는 것을 반영.
    if (CurrentSourceEditor$selection[[1]]$range$end[1] < bookmark_07_context$selection[[1]]$range$end[1]){
      line_number <- bookmark_07_context$selection[[1]]$range$end[1] + (length(CurrentSourceEditor$contents) - length(bookmark_07_context$contents))
      myposition <- rstudioapi::document_position(line_number, bookmark_07_context$selection[[1]]$range$end[2])
    }

    rstudioapi::setCursorPosition(position=myposition, # 위에서 저장한 정보를 이용하여, 커서 위치를 이전 작업하던 명령줄의 마지막 칸에 위치 시킴.
                                  id=CurrentSourceEditor$id)
    cat(paste(rep("=", 60), collapse =""), "\n")
    cat(paste0(crayon::bgCyan("Go to"), " ", bookmark_07_context$memo))
    cat(paste0("\n", bookmark_07_context$ts, "\n"))
  } else {
    cat("Warning!: There is no object bookmark_07_context")
  }
}

# Alt+Shift+m, Ctrl+8 (keypad)
bookmark_08 <- function(){
  if (exists("bookmark_08_context")){
    default <- bookmark_08_context$memo
    indication <- "Modified"
  } else {
    default <- "Bookmark 08: "
    indication <- "Created"
  }
  bookmark_08_context <- rstudioapi::getSourceEditorContext() # 먼저 작업 중인 script 파일에서, 정보를 저장.
  input <- svDialogs::dlgInput("Title of the Bookmark 08?: ", default=default)$res
  if (length(input)){
    Encoding(input) <- "UTF-8"
    bookmark_08_context$memo <- input
  } else {
    bookmark_08_context$memo <- "Bookmark 08: "
  }
  bookmark_08_context$ts <- Sys.time()
  assign("bookmark_08_context", bookmark_08_context, envir = parent.frame()) # 서로 독립적인 함수에서, 먼저 생성된 변수를 사용하기 위해 envir 옵션을 사용.
  cat(paste(rep("=", 60), collapse =""), "\n")
  cat(paste0(crayon::bgBlue(indication), " ", bookmark_08_context$memo))
  cat(paste0("\n", bookmark_08_context$ts, "\n"))
}

# Alt+Shift+b, Ctrl+8 (keypad)
go_to_bookmark_08 <- function(){
  if ("bookmark_08_context" %in% ls(pattern="bookmark_0", envir = parent.frame())){
    CurrentSourceEditor <- rstudioapi::getSourceEditorContext() # 돌아가기 전 작업하던 script의 정보를 저장.

    if (identical(bookmark_08_context$path, CurrentSourceEditor$path)){
    } else {
      rstudioapi::navigateToFile(file=bookmark_08_context$path,
                                 line = bookmark_08_context$selection[[1]]$range$end[1])
    }

    myposition <- bookmark_08_context$selection[[1]]$range$end

    # 혹시라도 이동한 문서의 위치에서 작업을 하여, 이전의 위치를 나타내는 line number에 변화가 있을 수도 있는 것을 반영.
    if (CurrentSourceEditor$selection[[1]]$range$end[1] < bookmark_08_context$selection[[1]]$range$end[1]){
      line_number <- bookmark_08_context$selection[[1]]$range$end[1] + (length(CurrentSourceEditor$contents) - length(bookmark_08_context$contents))
      myposition <- rstudioapi::document_position(line_number, bookmark_08_context$selection[[1]]$range$end[2])
    }

    rstudioapi::setCursorPosition(position=myposition, # 위에서 저장한 정보를 이용하여, 커서 위치를 이전 작업하던 명령줄의 마지막 칸에 위치 시킴.
                                  id=CurrentSourceEditor$id)
    cat(paste(rep("=", 60), collapse =""), "\n")
    cat(paste0(crayon::bgCyan("Go to"), " ", bookmark_08_context$memo))
    cat(paste0("\n", bookmark_08_context$ts, "\n"))
  } else {
    cat("Warning!: There is no object bookmark_08_context")
  }
}

# Alt+Shift+m, Ctrl+9 (keypad)
bookmark_09 <- function(){
  if (exists("bookmark_09_context")){
    default <- bookmark_09_context$memo
    indication <- "Modified"
  } else {
    default <- "Bookmark 09: "
    indication <- "Created"
  }
  bookmark_09_context <- rstudioapi::getSourceEditorContext() # 먼저 작업 중인 script 파일에서, 정보를 저장.
  input <- svDialogs::dlgInput("Title of the Bookmark 09?: ", default=default)$res
  if (length(input)){
    Encoding(input) <- "UTF-8"
    bookmark_09_context$memo <- input
  } else {
    bookmark_09_context$memo <- "Bookmark 09: "
  }
  bookmark_09_context$ts <- Sys.time()
  assign("bookmark_09_context", bookmark_09_context, envir = parent.frame()) # 서로 독립적인 함수에서, 먼저 생성된 변수를 사용하기 위해 envir 옵션을 사용.
  cat(paste(rep("=", 60), collapse =""), "\n")
  cat(paste0(crayon::bgBlue(indication), " ", bookmark_09_context$memo))
  cat(paste0("\n", bookmark_09_context$ts, "\n"))
}

# Alt+Shift+b, Ctrl+9 (keypad)
go_to_bookmark_09 <- function(){
  if ("bookmark_09_context" %in% ls(pattern="bookmark_0", envir = parent.frame())){
    CurrentSourceEditor <- rstudioapi::getSourceEditorContext() # 돌아가기 전 작업하던 script의 정보를 저장.

    if (identical(bookmark_09_context$path, CurrentSourceEditor$path)){
    } else {
      rstudioapi::navigateToFile(file=bookmark_09_context$path,
                                 line = bookmark_09_context$selection[[1]]$range$end[1])
    }

    myposition <- bookmark_09_context$selection[[1]]$range$end

    # 혹시라도 이동한 문서의 위치에서 작업을 하여, 이전의 위치를 나타내는 line number에 변화가 있을 수도 있는 것을 반영.
    if (CurrentSourceEditor$selection[[1]]$range$end[1] < bookmark_09_context$selection[[1]]$range$end[1]){
      line_number <- bookmark_09_context$selection[[1]]$range$end[1] + (length(CurrentSourceEditor$contents) - length(bookmark_09_context$contents))
      myposition <- rstudioapi::document_position(line_number, bookmark_09_context$selection[[1]]$range$end[2])
    }

    rstudioapi::setCursorPosition(position=myposition, # 위에서 저장한 정보를 이용하여, 커서 위치를 이전 작업하던 명령줄의 마지막 칸에 위치 시킴.
                                  id=CurrentSourceEditor$id)
    cat(paste(rep("=", 60), collapse =""), "\n")
    cat(paste0(crayon::bgCyan("Go to"), " ", bookmark_09_context$memo))
    cat(paste0("\n", bookmark_09_context$ts, "\n"))
  } else {
    cat("Warning!: There is no object bookmark_09_context")
  }
}

# Alt+Shift+b+c
bookmark_check <- function(){
  bookmarks <- ls(pattern="bookmark_", envir = parent.frame())
  cat(paste(rep("=", 60), collapse =""), "\n")
  cat(paste0(crayon::bgMagenta("All Bookmarks:")), "\n")
  for (i in 1:length(bookmarks)){
    bookmark <- paste0(bookmarks[i])
    text <- paste0(bookmark, "$memo")
    cat(eval(parse(text=text)), "\n\n")
  }
}
SeungmanLEEmago/Making-Addins documentation built on Dec. 18, 2021, 1:04 p.m.