![]() |
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.
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
(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")
Scheme]
(set-preference "test:pref" "on")
Scheme]
(preference-on? "test:pref")
Scheme]
Scheme]
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.
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.
Deletes preference name from the user preferences, so that it reverts to its default value, and calls the associated call-back.
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.
Returns #t if the value of preference name is "on".
Toggles the value of preference name between "on" and "off".
(set-boolean-preference name val)
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)
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.
Call the call-back associated to the preference name with its current value.