Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to disable auto double quotes matching #346

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/BracketInserter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ module BracketInserter

using OhMyREPL

# If a user writes an opening bracket
# automatically complete it with a closing bracket
# unless the next character is that closing bracket
mutable struct BracketInserterSettings
complete_brackets::Bool
end

import REPL
import REPL.LineEdit
import REPL.LineEdit: edit_insert, edit_move_left, edit_move_right, edit_backspace, edit_kill_region,
Expand All @@ -17,7 +10,6 @@ import REPL.LineEdit: edit_insert, edit_move_left, edit_move_right, edit_backspa
import REPL.Terminals.beep
import OhMyREPL.Prompt.rewrite_with_ANSI

const BRACKET_INSERTER = BracketInserterSettings(true)

function leftpeek(b::IOBuffer)
p = position(b)
Expand All @@ -42,7 +34,9 @@ function no_closing_bracket(left_peek, v)
end

const AUTOMATIC_BRACKET_MATCH = Ref(!Sys.iswindows())
const AUTOMATIC_STRING_LITERALS_MATCH = Ref(!Sys.iswindows() && !(VERSION >= v"1.10")) # TODO: is the iswindows needed for this? TODO: change default if a new Julia version makes this unnecessary
enable_autocomplete_brackets(v::Bool) = AUTOMATIC_BRACKET_MATCH[] = v
enable_autocomplete_string_literals(v::Bool) = AUTOMATIC_STRING_LITERALS_MATCH[] = v

const pkgmode = Ref{Any}()
import Pkg
Expand Down Expand Up @@ -114,7 +108,7 @@ function insert_into_keymap!(D::Dict)
D[v] = (s, o...) -> begin
b = buffer(s)

if AUTOMATIC_BRACKET_MATCH[]
if (v == '\"' && AUTOMATIC_STRING_LITERALS_MATCH[]) || (v != '\"' && AUTOMATIC_BRACKET_MATCH[])
# Next char is the quote symbol so just move right
if !eof(b) && peek(b) == v
edit_move_right(b)
Expand Down
3 changes: 2 additions & 1 deletion src/OhMyREPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ end

import REPL

export colorscheme!, colorschemes, enable_autocomplete_brackets, enable_highlight_markdown, enable_fzf, test_colorscheme
export colorscheme!, colorschemes, enable_autocomplete_brackets, enable_autocomplete_string_literals, enable_highlight_markdown, enable_fzf, test_colorscheme

const SUPPORTS_256_COLORS = !(Sys.iswindows() && VERSION < v"1.5.3")

Expand All @@ -25,6 +25,7 @@ include("BracketInserter.jl")
include("prompt.jl")

import .BracketInserter.enable_autocomplete_brackets
import .BracketInserter.enable_autocomplete_string_literals

function colorscheme!(name::String)
Passes.SyntaxHighlighter.activate!(
Expand Down
Loading