Skip to content

Commit

Permalink
Merge pull request #3778 from Hannah-Sten/ligatures-texoff
Browse files Browse the repository at this point in the history
Disable quotes inspection when TeX ligatures are disabled by fontspec
  • Loading branch information
PHPirates authored Dec 1, 2024
2 parents 2028196 + 8dc5cb5 commit 7b9cbda
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

### Added
* Disable quotes inspection when TeX ligatures are disabled by fontspec

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import com.intellij.psi.util.PsiTreeUtil.findChildrenOfType
import com.intellij.refactoring.suggested.extend
import nl.hannahsten.texifyidea.inspections.InsightGroup
import nl.hannahsten.texifyidea.inspections.TexifyInspectionBase
import nl.hannahsten.texifyidea.lang.LatexPackage
import nl.hannahsten.texifyidea.lang.commands.LatexGenericRegularCommand
import nl.hannahsten.texifyidea.psi.LatexNormalText
import nl.hannahsten.texifyidea.util.files.commandsInFileSet
import nl.hannahsten.texifyidea.util.files.document
import nl.hannahsten.texifyidea.util.parser.inMathContext
import nl.hannahsten.texifyidea.util.magic.PatternMagic.quotePattern
import nl.hannahsten.texifyidea.util.replaceString
import nl.hannahsten.texifyidea.util.magic.cmd
import nl.hannahsten.texifyidea.util.parser.inMathContext
import nl.hannahsten.texifyidea.util.parser.requiredParameter
import nl.hannahsten.texifyidea.util.replaceString
import nl.hannahsten.texifyidea.util.toTextRange

/**
Expand Down Expand Up @@ -65,6 +68,13 @@ class LatexQuoteInspection : TexifyInspectionBase() {
"``" to "''",
)
val commands = file.commandsInFileSet()

// When Ligatures=TeXOff is set, straight quotes will be used. This setting can be applied in certain fontspec commands
val fontspecCommands = LatexGenericRegularCommand.entries.filter { it.dependency == LatexPackage.FONTSPEC }.map { it.cmd }
if (commands.filter { it.name in fontspecCommands }.any { it.text.contains("ligatures=TeXOff", ignoreCase = true) }) {
return emptyList()
}

for (quoteMaker in quoteMakers) {
for (command in commands) {
val opener = command.requiredParameter(quoteMaker.openParam)
Expand Down
1 change: 1 addition & 0 deletions src/nl/hannahsten/texifyidea/lang/LatexPackage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ open class LatexPackage @JvmOverloads constructor(
val EUROSYM = LatexPackage("eurosym")
val FLOAT = LatexPackage("float")
val FONTENC = LatexPackage("fontenc")
val FONTSPEC = LatexPackage("fontspec")
val GAUSS = LatexPackage("gauss")
val GLOSSARIES = LatexPackage("glossaries")
val GLOSSARIESEXTRA = LatexPackage("glossaries-extra")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.CLEVEREF
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.COLOR
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.CSQUOTES
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.FONTENC
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.FONTSPEC
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.GLOSSARIES
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.GRAPHICX
import nl.hannahsten.texifyidea.lang.LatexPackage.Companion.MATHTOOLS
Expand Down Expand Up @@ -413,6 +414,15 @@ enum class LatexGenericRegularCommand(
LCNAMECREFS("lcnamecrefs", "label".asRequired(Argument.Type.LABEL), dependency = CLEVEREF),
LABELCREF("labelcref", "key".asRequired(Argument.Type.LABEL), dependency = CLEVEREF),
LABELCPAGEREF("labelcpageref", "key".asRequired(Argument.Type.LABEL), dependency = CLEVEREF),

// Fontspec
DEFAULTFONTFEATURES("defaultfontfeatures", "font names".asOptional(), "font features".asRequired(), dependency = FONTSPEC),
ADDFONTFEATURE("addfontfeature", "font features".asRequired(), dependency = FONTSPEC),
ADDFONTFEATURES("addfontfeatures", "font features".asRequired(), dependency = FONTSPEC),
SETMAINFONT("setmainfont", "font".asRequired(), "font features".asOptional(), dependency = FONTSPEC),
SETSANSFONT("setsansfont", "font".asRequired(), "font features".asOptional(), dependency = FONTSPEC),
SETMONOFONT("setmonofont", "font".asRequired(), "font features".asOptional(), dependency = FONTSPEC),
FONTSPEC_CMD("fontspec", "font".asRequired(), "font features".asOptional(), dependency = FONTSPEC),
;

override val identifier: String
Expand Down

0 comments on commit 7b9cbda

Please sign in to comment.