GNU TeXmacsUser manualReferenceAboutEnglish
User preferences

Preferences are used to store any information you need to keep across different runs of TeXmacs, like window position and size, active menu bars, etc. Internally they are stored in the file $TEXMACS_HOME_PATH/system/preferences.scm as a Scheme list of items like ("name" "value") which therefore has in principle no structure. The Scheme interface is defined in

kernel/texmacs/tm-preferences.scm

, on top of the glued C++ routines cpp-get-preference, cpp-set-preference, cpp-reset-preference, cpp-has-preference? and save-preferences. However, a good practice to avoid conflicts is to prefix your options by the name of the plugin or module you are creating, like in "gui:help-window-position".

The first step in defining a new preference is adding it with define-preferences and assigning a call-back function to handle changes in the preference. This is important for instance in menus, where a click on an item simply sets some preference to some value and it's up to the call-back to actually take the necessary actions.

Warning. One may not store the boolean values #t, #f directly into preferences. Instead one should use the strings "on" and "off". This is due to the internal storage of default values for preferences using ahash-table: a default value #f cannot be distinguished from an undefined default. Preference values are stored as strings; other values are converted using object->string, and converted back by get-preference only if the default value is not a string.

(define-preferences list)
(define new preferences with defaults and call-backs)

Each element of list is of the form ("somename" default-value notify-procedure) where notify-procedure is a procedure taking two arguments like this:

(define (notify-procedure property-name value) (do-things))

A default value is only set if no default value had been defined before. The call-back is also called once when the preference is defined.

Remember to use the strings "on" and "off" instead of booleans #t, #f.

Example

\(\Uparrow\)

Scheme]

(define (notify-test pref value)

(display* "Hey! " pref " changed to " value) (newline))

Scheme]

(define-preferences ("test:pref" "off" notify-test))

Scheme]

(get-preference "test:pref")

"off"

Scheme]

(set-preference "test:pref" "on")

Scheme]

(preference-on? "test:pref")

#t

Scheme]

(set-preference name value)
(set user preference)

Save preference name with value value. If the value changed, then call the call-back associated to this preference, as defined in define-preferences, and save the preferences to disk.

Remember to use the strings "on" and "off" instead of booleans #t, #f.

(append-preference name value)
(appends a value to the list for a preference)

This convenience function appends value to the list of values of preference name, or creates a list with one element in case the preference didn't exist. The call-back associated to this preference, as defined in define-preferences is called once the modification is done.

(reset-preference name)
(delete user preference)

Deletes preference name from the user preferences, so that it reverts to its default value, and calls the associated call-back.

(get-preference name)
(get user preference)

Returns the value of preference name. If the user did not set the preference, then its default value from define-preferences is returned, or the string "default" if no default value was defined.

(preference-on? name)
(test boolean user preference)

Returns #t if the value of preference name is "on".

(toggle-preference name)
(change value of boolean user preference)

Toggles the value of preference name between "on" and "off".

(set-boolean-preference name val)

(get-boolean-preference name)
(boolean preferences)

Set the preference name to "on" or "off" depending on the boolean val, resp. test whether it is "on".

(define-preference-names name (val pretty) …)

(set-pretty-preference name pretty)

(get-pretty-preference name)
(human readable preference values)

The macro define-preference-names associates human readable names pretty to the internal values val of the preference name. The routines set-pretty-preference and get-pretty-preference are variants of set-preference and get-preference which work with these human readable names; they are typically used in the preferences dialogue.

(notify-preference name)
(call the call-back of a preference)

Call the call-back associated to the preference name with its current value.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".