--- a/less.module
+++ b/less.module
@@ -61,7 +61,22 @@
   }
   
   $less_path = 'public://less/' . $less_dir;
+
+  // Get any theme.info settings and merge them into the passed settings
+  // (this incorporates functionality from attik's patch at http://drupal.org/node/1433948):
+  GLOBAL $theme_info, $theme;
+  $global_less_vars = array();
+  if (isset($theme_info->info) && isset($theme_info->info['less'])) {
+    $global_less_vars = (array) $theme_info->info['less'];
+    if (!theme_get_setting('less_use_default', $theme)) {
+      $global_less_vars += (array) theme_get_setting('less', $theme);
+    }
+  }
   
+  // Get any LESS functions declared via hook_less_register_function
+  // (this incorporates functionality from attik's patch at http://drupal.org/node/1433948):
+  $global_less_functions = (array) module_invoke_all("less_register_function");
+  
   foreach ($styles['#items'] as $key => $info) {
     $input_file = $info['data'];
     if (drupal_substr($input_file, -5) == '.less') {
@@ -98,12 +113,20 @@
         $less_args['functions'] = (array) $info['less']['functions'];
         $less_args['variables'] = (array) $info['less']['variables'];
       }
-
+      
+      // If $less_args['tag'] is not empty, modify the generated filename (dynamically create
+      // a new CSS file, allowing different variable/function assignments to be cached both
+      // server- and client-side):
       $output_file = $css_path . '/' . $less_args['tag'].basename($input_file, '.less');
       // correct file names of files not following the .css.less naming convention
       if (drupal_substr($output_file, -4) != '.css') {
         $output_file .= '.css';
       }
+      
+      // Merge $global_less_vars and $global_less_functions (defined via theme.info and hook)
+      // into the per-file array (defined at runtime by drupal_add_css()):
+      $less_args['variables'] += $global_less_vars;
+      $less_args['functions'] += $global_less_functions;
 
       if (!file_exists($output_file) || $less_args['expire']) {
         require_once($lessphp_include);
@@ -128,9 +151,11 @@
 
         try {
           // Register any PHP functions (THIS CAN BE VERY DANGEROUS, SINCE IT GIVES CSS ACCESS TO PHP FUNCTIONALITY!):
-          foreach ($less_args['functions'] as $less_func => $php_func) {
-            // Don't typecast $php_func, since as of PHP 5.3 it may be an anonymous function instead of a string.
-            $less->registerFunction(trim($less_func), $php_func);
+          if (method_exists($less, 'registerFunction')) {
+            foreach ($less_args['functions'] as $less_func => $php_func) {
+              // Don't typecast $php_func, since as of PHP 5.3 it may be an anonymous function instead of a string.
+              $less->registerFunction(trim($less_func), $php_func);
+            }
           }
           $output_data = $less->parse($data, $less_args['variables']);
           file_unmanaged_save_data($output_data, $output_file, FILE_EXISTS_REPLACE);
@@ -226,3 +251,74 @@
   
   return $lessphp_include;
 }
+
+
+/**
+ * Implements hook_form_alter().
+ */
+function less_form_system_theme_settings_alter(&$form, &$form_state) {
+  if (isset($form_state['build_info']['args'][0]) && ($theme_key = $form_state['build_info']['args'][0])) {
+    $themes = list_themes();
+    if (isset($themes[$theme_key]->info['less'])) {
+      array_unshift($form['#submit'], 'less_form_system_theme_settings_submit');
+
+      $theme_less = $themes[$theme_key]->info['less'];
+      $saved_settings = theme_get_setting('less', $theme_key);
+
+      $form['less_fs'] = array(
+        '#type' => 'fieldset',
+        '#title' => t('Less overrides'),
+        '#weight' => -1,
+        '#tree' => TRUE,
+      );
+      $form['less_fs']['less_use_default'] = array(
+        '#type' => 'checkbox',
+        '#title' => t('Use the default settings'),
+        '#default_value' => theme_get_setting('less_use_default', $theme_key),
+      );
+      $form['less_fs']['less'] = array(
+        '#type' => 'container',
+        '#states' => array(
+          'invisible' => array(
+            'input[name="less_fs[less_use_default]"]' => array('checked' => TRUE),
+          ),
+        ),
+      );
+      foreach ($theme_less as $key => $value) {
+        $value = isset($saved_settings[$key]) ? $saved_settings[$key] : $value;
+        if (strpos($value, '#') === FALSE) {
+          $form['less_fs']['less'][$key] = array(
+            '#type' => 'textfield',
+            '#title' => $key,
+            '#default_value' => $value,
+          );
+        }
+        else {
+          $form_state['less_hexcolors'][] = $key;
+          $form['less_fs']['less'][$key] = array(
+            '#type' => module_exists('jquery_colorpicker') ? 'jquery_colorpicker' : 'textfield',
+            '#title' => $key,
+            '#default_value' => str_replace('#', '', $value),
+          );
+        }
+      }
+    }
+  }
+}
+
+/**
+ * Save settings, alter structure first().
+ */
+function less_form_system_theme_settings_submit($form, &$form_state) {
+  less_flush_caches();
+
+  $form_state['values'] += $form_state['values']['less_fs'];
+  unset($form_state['values']['less_fs']);
+  if (isset($form_state['less_hexcolors']) && is_array($form_state['less_hexcolors'])) {
+    foreach ($form_state['less_hexcolors'] as $key) {
+      if (strpos($form_state['values']['less'][$key], '#') === FALSE) {
+        $form_state['values']['less'][$key] = '#' . $form_state['values']['less'][$key];
+      }
+    }
+  }
+}
\ No newline at end of file
