Skip to content

Instantly share code, notes, and snippets.

@layus
Last active June 23, 2016 12:39
Show Gist options
  • Save layus/09c1bf1aa1c7ada2893cbe3d0ac77ac6 to your computer and use it in GitHub Desktop.
Save layus/09c1bf1aa1c7ada2893cbe3d0ac77ac6 to your computer and use it in GitHub Desktop.
xserver.conf improvements via smart antiquotations.

This example shows how the generation of xserver.conf is impacted by the modification of semantics for antiquotations in multiline indented strings.

Three versions are presented here:

  • xserver.conf: The old version
  • xserver.conf-smart: The new version, note how many blank lines are removed, and block properly indented.
  • xserver.conf-smart-fixed: The version obtained with the new semantics after modifications from improve-x11.diff, in particular removing some cruft that reindents(!) blocks.

In particular, xserver.conf.diff shows the differences between xserver.conf and xserver.conf-smart-fixed.

--- xserver.conf-normal 2016-06-20 18:25:53.176692683 +0200
+++ xserver.conf-smart-fixed 2016-06-20 18:38:35.950736792 +0200
@@ -1,207 +1,124 @@
Section "ServerFlags"
Option "AllowMouseOpenFail" "on"
Option "DontZap" "on"
-
EndSection
Section "Module"
-
EndSection
Section "Monitor"
Identifier "Monitor[0]"
-
EndSection
Section "InputClass"
Identifier "Keyboard catchall"
MatchIsKeyboard "on"
Option "XkbRules" "base"
Option "XkbModel" "pc104"
Option "XkbLayout" "be"
Option "XkbOptions" "eurosign:e"
Option "XkbVariant" ""
EndSection
# Additional "InputClass" sections
-
Section "ServerLayout"
Identifier "Layout[all]"
-
# Reference the Screen sections for each driver. This will
# cause the X server to try each in turn.
Screen "Screen-ati[0]"
-Screen "Screen-cirrus[0]"
-Screen "Screen-intel[0]"
-Screen "Screen-vesa[0]"
-Screen "Screen-vmware[0]"
-Screen "Screen-modesetting[0]"
-
+ Screen "Screen-cirrus[0]"
+ Screen "Screen-intel[0]"
+ Screen "Screen-vesa[0]"
+ Screen "Screen-vmware[0]"
+ Screen "Screen-modesetting[0]"
EndSection
-
# For each supported driver, add a "Device" and "Screen"
# section.
Section "Device"
Identifier "Device-ati[0]"
Driver "ati"
-
-
-
EndSection
Section "Screen"
Identifier "Screen-ati[0]"
Device "Device-ati[0]"
-
-
-
-
-
-
-
-
EndSection
Section "Device"
Identifier "Device-cirrus[0]"
Driver "cirrus"
-
-
-
EndSection
Section "Screen"
Identifier "Screen-cirrus[0]"
Device "Device-cirrus[0]"
-
-
-
-
-
-
-
-
EndSection
Section "Device"
Identifier "Device-intel[0]"
Driver "intel"
-
-
-
EndSection
Section "Screen"
Identifier "Screen-intel[0]"
Device "Device-intel[0]"
-
-
-
-
-
-
-
-
EndSection
Section "Device"
Identifier "Device-vesa[0]"
Driver "vesa"
-
-
-
EndSection
Section "Screen"
Identifier "Screen-vesa[0]"
Device "Device-vesa[0]"
-
-
-
-
-
-
-
-
EndSection
Section "Device"
Identifier "Device-vmware[0]"
Driver "vmware"
-
-
-
EndSection
Section "Screen"
Identifier "Screen-vmware[0]"
Device "Device-vmware[0]"
-
-
-
-
-
-
-
-
EndSection
Section "Device"
Identifier "Device-modesetting[0]"
Driver "modesetting"
-
-
-
EndSection
Section "Screen"
Identifier "Screen-modesetting[0]"
Device "Device-modesetting[0]"
-
-
-
-
-
-
-
-
EndSection
-
-
# Automatically enable the synaptics driver for all touchpads.
Section "InputClass"
Identifier "synaptics touchpad catchall"
MatchIsTouchpad "on"
-
Driver "synaptics"
Option "MinSpeed" "1.0"
Option "MaxSpeed" "1.4"
Option "AccelFactor" "0.1"
Option "MaxTapTime" "180"
-Option "MaxTapMove" "220"
-Option "TapButton1" "1"
-Option "TapButton2" "2"
-Option "TapButton3" "3"
-
+ Option "MaxTapMove" "220"
+ Option "TapButton1" "1"
+ Option "TapButton2" "2"
+ Option "TapButton3" "3"
Option "ClickFinger1" "1"
Option "ClickFinger2" "2"
Option "ClickFinger3" "3"
Option "VertTwoFingerScroll" "1"
Option "HorizTwoFingerScroll" "1"
Option "VertEdgeScroll" "0"
Option "HorizEdgeScroll" "0"
-
-
-
-
-
-
EndSection
Section "ServerFlags"
Option "AllowMouseOpenFail" "on"
Option "DontZap" "on"
EndSection
Section "Module"
EndSection
Section "Monitor"
Identifier "Monitor[0]"
EndSection
Section "InputClass"
Identifier "Keyboard catchall"
MatchIsKeyboard "on"
Option "XkbRules" "base"
Option "XkbModel" "pc104"
Option "XkbLayout" "be"
Option "XkbOptions" "eurosign:e"
Option "XkbVariant" ""
EndSection
# Additional "InputClass" sections
Section "ServerLayout"
Identifier "Layout[all]"
# Reference the Screen sections for each driver. This will
# cause the X server to try each in turn.
Screen "Screen-ati[0]"
Screen "Screen-cirrus[0]"
Screen "Screen-intel[0]"
Screen "Screen-vesa[0]"
Screen "Screen-vmware[0]"
Screen "Screen-modesetting[0]"
EndSection
# For each supported driver, add a "Device" and "Screen"
# section.
Section "Device"
Identifier "Device-ati[0]"
Driver "ati"
EndSection
Section "Screen"
Identifier "Screen-ati[0]"
Device "Device-ati[0]"
EndSection
Section "Device"
Identifier "Device-cirrus[0]"
Driver "cirrus"
EndSection
Section "Screen"
Identifier "Screen-cirrus[0]"
Device "Device-cirrus[0]"
EndSection
Section "Device"
Identifier "Device-intel[0]"
Driver "intel"
EndSection
Section "Screen"
Identifier "Screen-intel[0]"
Device "Device-intel[0]"
EndSection
Section "Device"
Identifier "Device-vesa[0]"
Driver "vesa"
EndSection
Section "Screen"
Identifier "Screen-vesa[0]"
Device "Device-vesa[0]"
EndSection
Section "Device"
Identifier "Device-vmware[0]"
Driver "vmware"
EndSection
Section "Screen"
Identifier "Screen-vmware[0]"
Device "Device-vmware[0]"
EndSection
Section "Device"
Identifier "Device-modesetting[0]"
Driver "modesetting"
EndSection
Section "Screen"
Identifier "Screen-modesetting[0]"
Device "Device-modesetting[0]"
EndSection
# Automatically enable the synaptics driver for all touchpads.
Section "InputClass"
Identifier "synaptics touchpad catchall"
MatchIsTouchpad "on"
Driver "synaptics"
Option "MinSpeed" "1.0"
Option "MaxSpeed" "1.4"
Option "AccelFactor" "0.1"
Option "MaxTapTime" "180"
Option "MaxTapMove" "220"
Option "TapButton1" "1"
Option "TapButton2" "2"
Option "TapButton3" "3"
Option "ClickFinger1" "1"
Option "ClickFinger2" "2"
Option "ClickFinger3" "3"
Option "VertTwoFingerScroll" "1"
Option "HorizTwoFingerScroll" "1"
Option "VertEdgeScroll" "0"
Option "HorizEdgeScroll" "0"
EndSection
Section "ServerFlags"
Option "AllowMouseOpenFail" "on"
Option "DontZap" "on"
EndSection
Section "Module"
EndSection
Section "Monitor"
Identifier "Monitor[0]"
EndSection
Section "InputClass"
Identifier "Keyboard catchall"
MatchIsKeyboard "on"
Option "XkbRules" "base"
Option "XkbModel" "pc104"
Option "XkbLayout" "be"
Option "XkbOptions" "eurosign:e"
Option "XkbVariant" ""
EndSection
# Additional "InputClass" sections
Section "ServerLayout"
Identifier "Layout[all]"
# Reference the Screen sections for each driver. This will
# cause the X server to try each in turn.
Screen "Screen-ati[0]"
Screen "Screen-cirrus[0]"
Screen "Screen-intel[0]"
Screen "Screen-vesa[0]"
Screen "Screen-vmware[0]"
Screen "Screen-modesetting[0]"
EndSection
# For each supported driver, add a "Device" and "Screen"
# section.
Section "Device"
Identifier "Device-ati[0]"
Driver "ati"
EndSection
Section "Screen"
Identifier "Screen-ati[0]"
Device "Device-ati[0]"
EndSection
Section "Device"
Identifier "Device-cirrus[0]"
Driver "cirrus"
EndSection
Section "Screen"
Identifier "Screen-cirrus[0]"
Device "Device-cirrus[0]"
EndSection
Section "Device"
Identifier "Device-intel[0]"
Driver "intel"
EndSection
Section "Screen"
Identifier "Screen-intel[0]"
Device "Device-intel[0]"
EndSection
Section "Device"
Identifier "Device-vesa[0]"
Driver "vesa"
EndSection
Section "Screen"
Identifier "Screen-vesa[0]"
Device "Device-vesa[0]"
EndSection
Section "Device"
Identifier "Device-vmware[0]"
Driver "vmware"
EndSection
Section "Screen"
Identifier "Screen-vmware[0]"
Device "Device-vmware[0]"
EndSection
Section "Device"
Identifier "Device-modesetting[0]"
Driver "modesetting"
EndSection
Section "Screen"
Identifier "Screen-modesetting[0]"
Device "Device-modesetting[0]"
EndSection
# Automatically enable the synaptics driver for all touchpads.
Section "InputClass"
Identifier "synaptics touchpad catchall"
MatchIsTouchpad "on"
Driver "synaptics"
Option "MinSpeed" "1.0"
Option "MaxSpeed" "1.4"
Option "AccelFactor" "0.1"
Option "MaxTapTime" "180"
Option "MaxTapMove" "220"
Option "TapButton1" "1"
Option "TapButton2" "2"
Option "TapButton3" "3"
Option "ClickFinger1" "1"
Option "ClickFinger2" "2"
Option "ClickFinger3" "3"
Option "VertTwoFingerScroll" "1"
Option "HorizTwoFingerScroll" "1"
Option "VertEdgeScroll" "0"
Option "HorizEdgeScroll" "0"
EndSection
commit 1c28d73fd7ad41103efa92a011c8d3861d38cf17
Author: Guillaume Maudoux <[email protected]>
Date: Tue Jun 21 13:54:49 2016 +0200
Simplify expressions with smart antiquotations
diff --git a/nixos/modules/services/x11/xserver.nix b/nixos/modules/services/x11/xserver.nix
index dcf9f82..b911dc4 100644
--- a/nixos/modules/services/x11/xserver.nix
+++ b/nixos/modules/services/x11/xserver.nix
@@ -39,17 +39,9 @@ let
};
in imap mkHead cfg.xrandrHeads;
- xrandrDeviceSection = let
- monitors = flip map xrandrHeads (h: ''
- Option "monitor-${h.output}" "${h.name}"
- '');
- # First option is indented through the space in the config but any
- # subsequent options aren't so we need to apply indentation to
- # them here
- monitorsIndented = if length monitors > 1
- then singleton (head monitors) ++ map (m: " " + m) (tail monitors)
- else monitors;
- in concatStrings monitorsIndented;
+ xrandrDeviceSection = flip concatMapStrings xrandrHeads (h: ''
+ Option "monitor-${h.output}" "${h.name}"
+ '');
# Here we chain every monitor from the left to right, so we have:
# m4 right of m3 right of m2 right of m1 .----.----.----.----.
@@ -601,13 +593,10 @@ in
${optionalString (cfg.monitorSection != "") ''
Monitor "Monitor[0]"
''}
-
${cfg.screenSection}
-
${optionalString (cfg.defaultDepth != 0) ''
DefaultDepth ${toString cfg.defaultDepth}
''}
-
${optionalString
(driver.name != "virtualbox" &&
(cfg.resolutions != [] ||
@@ -627,7 +616,6 @@ in
'';
in concatMapStrings f [8 16 24]
)}
-
EndSection
'')}
Section "ServerFlags"
Option "AllowMouseOpenFail" "on"
Option "DontZap" "on"
EndSection
Section "Module"
EndSection
Section "Monitor"
Identifier "Monitor[0]"
EndSection
Section "InputClass"
Identifier "Keyboard catchall"
MatchIsKeyboard "on"
Option "XkbRules" "base"
Option "XkbModel" "pc104"
Option "XkbLayout" "be"
Option "XkbOptions" "eurosign:e"
Option "XkbVariant" ""
EndSection
# Additional "InputClass" sections
Section "ServerLayout"
Identifier "Layout[all]"
# Reference the Screen sections for each driver. This will
# cause the X server to try each in turn.
Screen "Screen-ati[0]"
Screen "Screen-cirrus[0]"
Screen "Screen-intel[0]"
Screen "Screen-vesa[0]"
Screen "Screen-vmware[0]"
Screen "Screen-modesetting[0]"
EndSection
# For each supported driver, add a "Device" and "Screen"
# section.
Section "Device"
Identifier "Device-ati[0]"
Driver "ati"
EndSection
Section "Screen"
Identifier "Screen-ati[0]"
Device "Device-ati[0]"
EndSection
Section "Device"
Identifier "Device-cirrus[0]"
Driver "cirrus"
EndSection
Section "Screen"
Identifier "Screen-cirrus[0]"
Device "Device-cirrus[0]"
EndSection
Section "Device"
Identifier "Device-intel[0]"
Driver "intel"
EndSection
Section "Screen"
Identifier "Screen-intel[0]"
Device "Device-intel[0]"
EndSection
Section "Device"
Identifier "Device-vesa[0]"
Driver "vesa"
EndSection
Section "Screen"
Identifier "Screen-vesa[0]"
Device "Device-vesa[0]"
EndSection
Section "Device"
Identifier "Device-vmware[0]"
Driver "vmware"
EndSection
Section "Screen"
Identifier "Screen-vmware[0]"
Device "Device-vmware[0]"
EndSection
Section "Device"
Identifier "Device-modesetting[0]"
Driver "modesetting"
EndSection
Section "Screen"
Identifier "Screen-modesetting[0]"
Device "Device-modesetting[0]"
EndSection
# Automatically enable the synaptics driver for all touchpads.
Section "InputClass"
Identifier "synaptics touchpad catchall"
MatchIsTouchpad "on"
Driver "synaptics"
Option "MinSpeed" "1.0"
Option "MaxSpeed" "1.4"
Option "AccelFactor" "0.1"
Option "MaxTapTime" "180"
Option "MaxTapMove" "220"
Option "TapButton1" "1"
Option "TapButton2" "2"
Option "TapButton3" "3"
Option "ClickFinger1" "1"
Option "ClickFinger2" "2"
Option "ClickFinger3" "3"
Option "VertTwoFingerScroll" "1"
Option "HorizTwoFingerScroll" "1"
Option "VertEdgeScroll" "0"
Option "HorizEdgeScroll" "0"
EndSection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment