<commit_before>package isabelle.eclipse.ui.preferences

import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer
import org.eclipse.jface.preference.IPreferenceStore
import org.eclipse.jface.resource.StringConverter
import org.eclipse.swt.graphics.RGB

import isabelle.eclipse.ui.IsabelleUIPlugin
import isabelle.eclipse.ui.preferences.IsabelleSyntaxClasses._


/** Initialises preferences for syntax colours (and styles).
  * The syntax styles are defined in {@link IsabelleSyntaxClasses}.
  *
  * @author <NAME>
  */
object ColourPreferenceInitializer {

  def initializeDefaultPreferences() {
    setDefaultsForSyntaxClasses(IsabelleUIPlugin.getPreferences())
  }
  
  private def setDefaultsForSyntaxClass(
    syntaxClass: IsabelleSyntaxClass,
    foreground: RGB,
    background: Option[RGB] = None,
    bold: Boolean = false,
    italic: Boolean = false,
    strikethrough: Boolean = false,
    underline: Boolean = false)(implicit prefs: IPreferenceStore) =
    {
      prefs.setDefault(syntaxClass.foregroundKey, StringConverter.asString(foreground))
      background foreach (bg =>
        prefs.setDefault(syntaxClass.backgroundKey, StringConverter.asString(bg)))
      prefs.setDefault(syntaxClass.boldKey, bold)
      prefs.setDefault(syntaxClass.italicKey, italic)
      prefs.setDefault(syntaxClass.strikethroughKey, strikethrough)
      prefs.setDefault(syntaxClass.underlineKey, underline)
    }

  private def setDefaultsForSyntaxClasses(implicit prefs: IPreferenceStore) {
    
    val black = new RGB(0, 0, 0)
    val red = new RGB(255, 0, 0)
    val green = new RGB(0, 128, 0)
    val blue = new RGB(0, 0, 255)
    val chocolate = new RGB(210, 105, 30)
    val darkRed = new RGB(139, 0, 0)
    val keyword1 = new RGB(0, 102, 153)
    val keyword2 = new RGB(0, 153, 102)
    val keyword3 = new RGB(43, 157, 255)
    val quoted = new RGB(240, 240, 240)
    
    setDefaultsForSyntaxClass(COMMENT, new RGB(204, 0, 0))
    setDefaultsForSyntaxClass(VERBATIM, black, Some(quoted))
    setDefaultsForSyntaxClass(STRING, black, Some(quoted))
    setDefaultsForSyntaxClass(KEYWORD, keyword1, bold = true)
    setDefaultsForSyntaxClass(KEYWORD2, keyword2, bold = true)
    setDefaultsForSyntaxClass(OPERATOR, black, bold = true)
    setDefaultsForSyntaxClass(LITERAL, keyword1)
    setDefaultsForSyntaxClass(DELIMITER, black)
    setDefaultsForSyntaxClass(TYPE, new RGB(160, 32, 240))
    setDefaultsForSyntaxClass(FREE, blue)
    setDefaultsForSyntaxClass(SKOLEM, chocolate)
    setDefaultsForSyntaxClass(BOUND, green)
    setDefaultsForSyntaxClass(VAR, new RGB(0, 0, 155))
    setDefaultsForSyntaxClass(INNER_STRING, chocolate)
    setDefaultsForSyntaxClass(INNER_COMMENT, darkRed)
    setDefaultsForSyntaxClass(DYN_FACT, new RGB(123, 164, 40))
    setDefaultsForSyntaxClass(ANTIQ, blue)
    setDefaultsForSyntaxClass(ML_KEYWORD, keyword1, bold = true)
    setDefaultsForSyntaxClass(ML_NUMERAL, red)
    setDefaultsForSyntaxClass(ML_STRING, chocolate)
    setDefaultsForSyntaxClass(ML_COMMENT, darkRed)
    
    setDefaultsForSyntaxClass(CMD, keyword1, bold = true)
    setDefaultsForSyntaxClass(CMD_SCRIPT, new RGB(246, 52, 36))
    setDefaultsForSyntaxClass(CMD_GOAL, keyword3, bold = true)
  }

}<commit_msg>make foreground colour preference optional<commit_after>package isabelle.eclipse.ui.preferences

import org.eclipse.jface.preference.IPreferenceStore
import org.eclipse.jface.resource.StringConverter
import org.eclipse.swt.graphics.RGB

import isabelle.eclipse.ui.IsabelleUIPlugin
import isabelle.eclipse.ui.preferences.IsabelleSyntaxClasses._


/** Initialises preferences for syntax colours (and styles).
  * The syntax styles are defined in {@link IsabelleSyntaxClasses}.
  *
  * @author <NAME>
  */
object ColourPreferenceInitializer {

  def initializeDefaultPreferences() {
    setDefaultsForSyntaxClasses(IsabelleUIPlugin.getPreferences())
  }
  
  private def setDefaultsForSyntaxClass(
    syntaxClass: IsabelleSyntaxClass,
    foreground: Option[RGB] = None,
    background: Option[RGB] = None,
    bold: Boolean = false,
    italic: Boolean = false,
    strikethrough: Boolean = false,
    underline: Boolean = false)(implicit prefs: IPreferenceStore) =
    {
      foreground foreach (fg =>
        prefs.setDefault(syntaxClass.foregroundKey, StringConverter.asString(fg)))
      background foreach (bg =>
        prefs.setDefault(syntaxClass.backgroundKey, StringConverter.asString(bg)))
      prefs.setDefault(syntaxClass.boldKey, bold)
      prefs.setDefault(syntaxClass.italicKey, italic)
      prefs.setDefault(syntaxClass.strikethroughKey, strikethrough)
      prefs.setDefault(syntaxClass.underlineKey, underline)
    }

  private def setDefaultsForSyntaxClasses(implicit prefs: IPreferenceStore) {
    
    val black = rgb(0, 0, 0)
    val red = rgb(255, 0, 0)
    val green = rgb(0, 128, 0)
    val blue = rgb(0, 0, 255)
    val chocolate = rgb(210, 105, 30)
    val darkRed = rgb(139, 0, 0)
    val keyword1 = rgb(0, 102, 153)
    val keyword2 = rgb(0, 153, 102)
    val keyword3 = rgb(43, 157, 255)
    val quoted = rgb(240, 240, 240)
    
    setDefaultsForSyntaxClass(COMMENT, rgb(204, 0, 0))
    setDefaultsForSyntaxClass(VERBATIM, black, quoted)
    setDefaultsForSyntaxClass(STRING, black, quoted)
    setDefaultsForSyntaxClass(KEYWORD, keyword1, bold = true)
    setDefaultsForSyntaxClass(KEYWORD2, keyword2, bold = true)
    setDefaultsForSyntaxClass(OPERATOR, black, bold = true)
    setDefaultsForSyntaxClass(LITERAL, keyword1)
    setDefaultsForSyntaxClass(DELIMITER, black)
    setDefaultsForSyntaxClass(TYPE, rgb(160, 32, 240))
    setDefaultsForSyntaxClass(FREE, blue)
    setDefaultsForSyntaxClass(SKOLEM, chocolate)
    setDefaultsForSyntaxClass(BOUND, green)
    setDefaultsForSyntaxClass(VAR, rgb(0, 0, 155))
    setDefaultsForSyntaxClass(INNER_STRING, chocolate)
    setDefaultsForSyntaxClass(INNER_COMMENT, darkRed)
    setDefaultsForSyntaxClass(DYN_FACT, rgb(123, 164, 40))
    setDefaultsForSyntaxClass(ANTIQ, blue)
    setDefaultsForSyntaxClass(ML_KEYWORD, keyword1, bold = true)
    setDefaultsForSyntaxClass(ML_NUMERAL, red)
    setDefaultsForSyntaxClass(ML_STRING, chocolate)
    setDefaultsForSyntaxClass(ML_COMMENT, darkRed)
    
    setDefaultsForSyntaxClass(CMD, keyword1, bold = true)
    setDefaultsForSyntaxClass(CMD_SCRIPT, rgb(246, 52, 36))
    setDefaultsForSyntaxClass(CMD_GOAL, keyword3, bold = true)
  }
  
  private def rgb(r: Int, g: Int, b: Int): Option[RGB] = Some(new RGB(r, g, b))

}
{'fraction_non_alphanumeric': 0.0925754775107825, 'fraction_numerical': 0.03234750462107209, 'mean_word_length': 4.695614035087719, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3407600', 'n_tokens_mistral': 2286, 'n_tokens_neox': 2020, 'n_words': 438}