Skip to content

Commit

Permalink
Merge pull request #3820 from Hannah-Sten/autocompile
Browse files Browse the repository at this point in the history
Convert autocompile settings to combobox and add setting to disable in power save mode
  • Loading branch information
PHPirates authored Dec 24, 2024
2 parents 2033bea + b398880 commit 854b3bf
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 28 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
## [Unreleased]

### Added
* Add option to disable automatic compilation in power save mode
* Convert automatic compilation settings to a combobox
* Add checkboxes to graphic insertion wizard for relative width or height

### Fixed

## [0.9.10-alpha.4] - 2024-12-21

### Added

* Add sections to breadcrumbs
* Improve performance when starting a run configuration and when using autocompletion directly after starting the IDE
* Change order in structure view to match source file and sectioning level
Expand Down
7 changes: 6 additions & 1 deletion Writerside/topics/Running-a-LaTeX-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,17 @@ Currently the automatic compilation is only triggered when you type in a documen

![autocompile](autocompile.gif)

## Automatic compilation only when the document is saved.
### Automatic compilation only when the document is saved.
You can enable this in TeXiFy settings.
When enabled, auto compilation will only run when the file is actually saved to disk, instead of after every change.
To configure when a file is saved to disk (for example after a certain idle time), go to <ui-path>Settings | Appearance | System Settings</ui-path>.
Also see [https://www.jetbrains.com/help/idea/saving-and-reverting-changes.html](https://www.jetbrains.com/help/idea/saving-and-reverting-changes.html)

### Disable automatic compilation in power save mode

If you select this option, automatic compilation will always be on, except when power save mode is enabled, which can be done via <ui-path>File | Power Save Mode</ui-path>.
There are various other plugins which can automatically enable power save mode in certain situations.

### Automatic compilation support by compilers

Some compilers, at least latexmk and tectonic, also support automatic compilation.
Expand Down
10 changes: 5 additions & 5 deletions Writerside/topics/TeXiFy-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ If you disable this, consider if TeXiFy should support your use case and please
By default, when using a remote library (see [Tool Windows](Tool-Windows.md#remote-libraries)), any entries that you select in autocompletion will be copied to the local BibTeX file.
This settings disables that, which can be useful if you are including BibTeX files in a way that cannot be parsed by TeXiFy.

## Option to enable automatic compilation
_Since b0.6.8_

See [Support for automatic compilation](Running-a-LaTeX-file.md#automatic-compilation).

## Option to enable continuous preview of math and TikZ environments
_Since b0.6.7_

Expand Down Expand Up @@ -142,6 +137,11 @@ For more advantages, see [https://tex.stackexchange.com/questions/39285/whats-th

Choose what method to use to convert HTML to LaTeX when pasting from clipboard, see [Tools](Tools.md#paste-html-into-latex)

## Options for automatic compilation
_Since b0.6.8_

See [Support for automatic compilation](Running-a-LaTeX-file.md#automatic-compilation).

## Conventions
These settings can be found in <ui-path>File | Settings | Languages & Frameworks | TeXiFy | Conventions</ui-path> and allow you to configure Latex code conventions that apply either globally or for the current project.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import nl.hannahsten.texifyidea.settings.TexifySettings
class AutoCompileDoneListener : ProcessListener {

override fun processTerminated(event: ProcessEvent) {
if (TexifySettings.getInstance().autoCompile) {
AutoCompileState.compileDone()
if (TexifySettings.getInstance().isAutoCompileEnabled()) {
AutoCompileState.scheduleCompilationIfNecessary()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AutocompileHandler : TypedHandlerDelegate() {
override fun charTyped(char: Char, project: Project, editor: Editor, file: PsiFile): Result {
run {
// Only do this for latex files and if the option is enabled
if (file.fileType != LatexFileType || !TexifySettings.getInstance().autoCompile || TexifySettings.getInstance().autoCompileOnSaveOnly) {
if (file.fileType != LatexFileType || !TexifySettings.getInstance().isAutoCompileEnabled()) {
return@run
}

Expand All @@ -32,7 +32,7 @@ class AutoCompileBackspacehandler : BackspaceHandlerDelegate() {

override fun beforeCharDeleted(c: Char, file: PsiFile, editor: Editor) {
val project = editor.project
if (file.isLatexFile() && project != null && TexifySettings.getInstance().autoCompile && !TexifySettings.getInstance().autoCompileOnSaveOnly) {
if (file.isLatexFile() && project != null && TexifySettings.getInstance().isAutoCompileEnabled()) {
AutoCompileState.documentChanged(project)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object AutoCompileState {
* Tell the state a compilation has just finished.
*/
@Synchronized
fun compileDone() {
fun scheduleCompilationIfNecessary() {
// Only compile again if needed
if (hasChanged) {
scheduleCompilation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import nl.hannahsten.texifyidea.settings.TexifySettings
class AutoCompileVfsListener : AsyncFileListener {

override fun prepareChange(events: MutableList<out VFileEvent>): ChangeApplier? {
if (!TexifySettings.getInstance().autoCompileOnSaveOnly || !events.any { it.file?.fileType == LatexFileType }) return null
if (TexifySettings.getInstance().autoCompileOption != TexifySettings.AutoCompile.AFTER_DOCUMENT_SAVE || !events.any { it.file?.fileType == LatexFileType }) return null
return object : ChangeApplier {
override fun afterVfsChange() {
super.afterVfsChange()
Expand Down
13 changes: 6 additions & 7 deletions src/nl/hannahsten/texifyidea/settings/TexifyConfigurable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ class TexifyConfigurable : SearchableConfigurable {
private var automaticItemInItemize: JBCheckBox? = null
private var automaticDependencyCheck: JBCheckBox? = null
private var automaticBibtexImport: JBCheckBox? = null
private var autoCompile: JBCheckBox? = null
private var autoCompileOnSaveOnly: JBCheckBox? = null
private var continuousPreview: JBCheckBox? = null
private var includeBackslashInSelection: JBCheckBox? = null
private var showPackagesInStructureView: JBCheckBox? = null
Expand All @@ -35,6 +33,7 @@ class TexifyConfigurable : SearchableConfigurable {
private var latexIndentOptions: RawCommandLineEditor? = null
private var automaticQuoteReplacement: ComboBox<String>? = null
private var htmlPasteTranslator: ComboBox<String>? = null
private var autoCompileOption: ComboBox<String>? = null

/**
* Map UI variables to underlying setting variables
Expand All @@ -45,8 +44,6 @@ class TexifyConfigurable : SearchableConfigurable {
Pair(::automaticItemInItemize, settings::automaticItemInItemize),
Pair(::automaticDependencyCheck, settings::automaticDependencyCheck),
Pair(::automaticBibtexImport, settings::automaticBibtexImport),
Pair(::autoCompile, settings::autoCompile),
Pair(::autoCompileOnSaveOnly, settings::autoCompileOnSaveOnly),
Pair(::continuousPreview, settings::continuousPreview),
Pair(::includeBackslashInSelection, settings::includeBackslashInSelection),
Pair(::showPackagesInStructureView, settings::showPackagesInStructureView),
Expand All @@ -69,8 +66,6 @@ class TexifyConfigurable : SearchableConfigurable {
automaticItemInItemize = addCheckbox("Automatically insert '\\item' in itemize-like environments on pressing enter")
automaticDependencyCheck = addCheckbox("Automatically check for required package dependencies and insert them")
automaticBibtexImport = addCheckbox("Automatically copy BibTeX entries from remote libraries to the local library")
autoCompile = addCheckbox("Automatic compilation (warning: can cause high CPU usage)")
autoCompileOnSaveOnly = addCheckbox("Automatic compilation only after document save")
continuousPreview = addCheckbox("Automatically refresh preview of math and TikZ pictures")
includeBackslashInSelection = addCheckbox("Include the backslash in the selection when selecting a LaTeX command")
showPackagesInStructureView = addCheckbox("Show LaTeX package files in structure view (warning: structure view will take more time to load)")
Expand All @@ -80,6 +75,7 @@ class TexifyConfigurable : SearchableConfigurable {
latexIndentOptions = addCommandLineEditor("Latexindent", TexifySettingsState().latexIndentOptions)
automaticQuoteReplacement = addComboBox("Smart quote substitution: ", "Off", "TeX ligatures", "TeX commands", "csquotes")
htmlPasteTranslator = addComboBox("HTML paste translator", "Built-in", "Pandoc", "Disabled")
autoCompileOption = addComboBox("Automatic compilation", "Off", "Always", "After document save", "Disable in power save mode")
}
)
}
Expand Down Expand Up @@ -138,7 +134,8 @@ class TexifyConfigurable : SearchableConfigurable {
textidoteOptions?.text != settings.textidoteOptions ||
latexIndentOptions?.text != settings.latexIndentOptions ||
automaticQuoteReplacement?.selectedIndex != settings.automaticQuoteReplacement.ordinal ||
htmlPasteTranslator?.selectedIndex != settings.htmlPasteTranslator.ordinal
htmlPasteTranslator?.selectedIndex != settings.htmlPasteTranslator.ordinal ||
autoCompileOption?.selectedIndex != settings.autoCompileOption.ordinal
}

override fun apply() {
Expand All @@ -149,6 +146,7 @@ class TexifyConfigurable : SearchableConfigurable {
settings.latexIndentOptions = latexIndentOptions?.text ?: ""
settings.automaticQuoteReplacement = TexifySettings.QuoteReplacement.entries.toTypedArray()[automaticQuoteReplacement?.selectedIndex ?: 0]
settings.htmlPasteTranslator = TexifySettings.HtmlPasteTranslator.entries.toTypedArray()[htmlPasteTranslator?.selectedIndex ?: 0]
settings.autoCompileOption = TexifySettings.AutoCompile.entries.toTypedArray()[autoCompileOption?.selectedIndex ?: 0]
}

override fun reset() {
Expand All @@ -159,5 +157,6 @@ class TexifyConfigurable : SearchableConfigurable {
latexIndentOptions?.text = settings.latexIndentOptions
automaticQuoteReplacement?.selectedIndex = settings.automaticQuoteReplacement.ordinal
htmlPasteTranslator?.selectedIndex = settings.htmlPasteTranslator.ordinal
autoCompileOption?.selectedIndex = settings.autoCompileOption.ordinal
}
}
22 changes: 16 additions & 6 deletions src/nl/hannahsten/texifyidea/settings/TexifySettings.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package nl.hannahsten.texifyidea.settings

import com.intellij.ide.PowerSaveMode
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.PersistentStateComponent
import com.intellij.openapi.components.RoamingType
Expand Down Expand Up @@ -38,13 +39,18 @@ class TexifySettings : PersistentStateComponent<TexifySettingsState> {
DISABLED,
}

enum class AutoCompile {
OFF,
ALWAYS,
AFTER_DOCUMENT_SAVE,
DISABLE_ON_POWER_SAVE,
}

var automaticSecondInlineMathSymbol = true
var automaticUpDownBracket = true
var automaticItemInItemize = true
var automaticDependencyCheck = true
var automaticBibtexImport = true
var autoCompile = false
var autoCompileOnSaveOnly = false
var continuousPreview = false
var includeBackslashInSelection = false
var showPackagesInStructureView = false
Expand All @@ -54,6 +60,7 @@ class TexifySettings : PersistentStateComponent<TexifySettingsState> {
var latexIndentOptions = ""
var automaticQuoteReplacement = QuoteReplacement.NONE
var htmlPasteTranslator = HtmlPasteTranslator.BUILTIN
var autoCompileOption = AutoCompile.OFF

/**
* Backwards compatibility. This value is never altered, only read from/to memory.
Expand All @@ -70,8 +77,6 @@ class TexifySettings : PersistentStateComponent<TexifySettingsState> {
automaticItemInItemize = automaticItemInItemize,
automaticDependencyCheck = automaticDependencyCheck,
automaticBibtexImport = automaticBibtexImport,
autoCompile = autoCompile,
autoCompileOnSaveOnly = autoCompileOnSaveOnly,
continuousPreview = continuousPreview,
includeBackslashInSelection = includeBackslashInSelection,
showPackagesInStructureView = showPackagesInStructureView,
Expand All @@ -81,6 +86,7 @@ class TexifySettings : PersistentStateComponent<TexifySettingsState> {
latexIndentOptions = latexIndentOptions,
automaticQuoteReplacement = automaticQuoteReplacement,
htmlPasteTranslator = htmlPasteTranslator,
autoCompileOption = autoCompileOption,
pdfViewer = pdfViewer
)
}
Expand All @@ -91,8 +97,6 @@ class TexifySettings : PersistentStateComponent<TexifySettingsState> {
automaticItemInItemize = state.automaticItemInItemize
automaticDependencyCheck = state.automaticDependencyCheck
automaticBibtexImport = state.automaticBibtexImport
autoCompile = state.autoCompile
autoCompileOnSaveOnly = state.autoCompileOnSaveOnly
continuousPreview = state.continuousPreview
includeBackslashInSelection = state.includeBackslashInSelection
showPackagesInStructureView = state.showPackagesInStructureView
Expand All @@ -102,6 +106,12 @@ class TexifySettings : PersistentStateComponent<TexifySettingsState> {
latexIndentOptions = state.latexIndentOptions
automaticQuoteReplacement = state.automaticQuoteReplacement
htmlPasteTranslator = state.htmlPasteTranslator
// Backwards compatibility
autoCompileOption = state.autoCompileOption ?: if (state.autoCompileOnSaveOnly) AutoCompile.AFTER_DOCUMENT_SAVE else if (state.autoCompile) AutoCompile.ALWAYS else AutoCompile.OFF
pdfViewer = state.pdfViewer
}

fun isAutoCompileEnabled(): Boolean {
return autoCompileOption == AutoCompile.ALWAYS || (!PowerSaveMode.isEnabled() && autoCompileOption == AutoCompile.DISABLE_ON_POWER_SAVE)
}
}
6 changes: 4 additions & 2 deletions src/nl/hannahsten/texifyidea/settings/TexifySettingsState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ data class TexifySettingsState(
var automaticItemInItemize: Boolean = true,
var automaticDependencyCheck: Boolean = true,
var automaticBibtexImport: Boolean = true,
var autoCompile: Boolean = false,
var autoCompileOnSaveOnly: Boolean = false,
var continuousPreview: Boolean = false,
var includeBackslashInSelection: Boolean = false,
var showPackagesInStructureView: Boolean = false,
Expand All @@ -21,6 +19,10 @@ data class TexifySettingsState(
var latexIndentOptions: String = "",
var automaticQuoteReplacement: TexifySettings.QuoteReplacement = TexifySettings.QuoteReplacement.NONE,
var htmlPasteTranslator: TexifySettings.HtmlPasteTranslator = TexifySettings.HtmlPasteTranslator.BUILTIN,
var autoCompileOption: TexifySettings.AutoCompile? = null,
var missingLabelMinimumLevel: LatexCommand = LatexGenericRegularCommand.SUBSECTION,
// Kept for backwards compatibility
var autoCompile: Boolean = false,
var autoCompileOnSaveOnly: Boolean = false,
var pdfViewer: InternalPdfViewer = InternalPdfViewer.firstAvailable
)

0 comments on commit 854b3bf

Please sign in to comment.