From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Simen =?UTF-8?Q?Heggest=C3=B8yl?= Newsgroups: gmane.emacs.bugs Subject: bug#27881: New major mode: Less mode Date: Sun, 30 Jul 2017 19:53:03 +0200 Message-ID: <1501437183.13205.0@smtp.gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-p4GrjrrZxOwb/2G34Bou" X-Trace: blaine.gmane.org 1501437268 27808 195.159.176.226 (30 Jul 2017 17:54:28 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 30 Jul 2017 17:54:28 +0000 (UTC) Cc: Steve Purcell , Tom Tromey , Stefan Monnier , Dmitry Gutov To: 27881@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jul 30 19:54:16 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dbsPp-0006Ir-6b for geb-bug-gnu-emacs@m.gmane.org; Sun, 30 Jul 2017 19:54:09 +0200 Original-Received: from localhost ([::1]:56069 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dbsPu-0000XM-PO for geb-bug-gnu-emacs@m.gmane.org; Sun, 30 Jul 2017 13:54:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36037) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dbsPl-0000Vp-QY for bug-gnu-emacs@gnu.org; Sun, 30 Jul 2017 13:54:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dbsPi-0005R7-FY for bug-gnu-emacs@gnu.org; Sun, 30 Jul 2017 13:54:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:60058) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dbsPi-0005QW-9u for bug-gnu-emacs@gnu.org; Sun, 30 Jul 2017 13:54:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dbsPi-0002aq-4G for bug-gnu-emacs@gnu.org; Sun, 30 Jul 2017 13:54:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Simen =?UTF-8?Q?Heggest=C3=B8yl?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 30 Jul 2017 17:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 27881 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.15014372169934 (code B ref -1); Sun, 30 Jul 2017 17:54:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 30 Jul 2017 17:53:36 +0000 Original-Received: from localhost ([127.0.0.1]:34502 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dbsPD-0002a6-OC for submit@debbugs.gnu.org; Sun, 30 Jul 2017 13:53:35 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:45006) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dbsPB-0002Zt-FL for submit@debbugs.gnu.org; Sun, 30 Jul 2017 13:53:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dbsP3-0004qP-Az for submit@debbugs.gnu.org; Sun, 30 Jul 2017 13:53:24 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:37987) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dbsP3-0004px-6X for submit@debbugs.gnu.org; Sun, 30 Jul 2017 13:53:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35947) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dbsP0-0000Ke-6W for bug-gnu-emacs@gnu.org; Sun, 30 Jul 2017 13:53:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dbsOw-0004lF-1o for bug-gnu-emacs@gnu.org; Sun, 30 Jul 2017 13:53:18 -0400 Original-Received: from mail-lf0-x243.google.com ([2a00:1450:4010:c07::243]:35381) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dbsOr-0004gT-Jn for bug-gnu-emacs@gnu.org; Sun, 30 Jul 2017 13:53:13 -0400 Original-Received: by mail-lf0-x243.google.com with SMTP id w199so10787252lff.2 for ; Sun, 30 Jul 2017 10:53:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:subject:to:cc:message-id:mime-version; bh=MJRyAqXX6fMkX94FuSbdK2pB2lVmwX5p2ZKu1jOaqoE=; b=etVju6Wg2B9GvyMAS1VeHN4UyjuNdjbZeq5iSsqregfNtgbZHfte7DCaLIxSWTe7vx A1uS6Aw63Lt6hAzvzfaWid1VjiuLDWnTNJGXIJjnqmzxqYMjqNy86Jnl7A5l/i34ftzr 0oZJzTv6eX/5LMuSVJFUw3C703J75S90dt6qo04CFDEnyN735RtHZlnjBwg3iI7w9yIh CBbPnsU53vIpO5wD2Z97IzoyhsWdXLSykawfF8+7O0xtZpQRtPDRJV5EQadgHy/E6AhT wcY9eFcYn9+R4WrnDB2IPWJFn/7kAA2Mt5bekmn2j3Me4yQhZsW/LxZRkc+ffE8lE8b4 DBmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:subject:to:cc:message-id:mime-version; bh=MJRyAqXX6fMkX94FuSbdK2pB2lVmwX5p2ZKu1jOaqoE=; b=XbqWIMgxzKy8vk8mhhUtPnxp4oLS//5uBtiaMVd4JJK7nuMsBSNMfL9immGONARZl/ M4wa7JWWqKM/kXAgExyvqDe4u8hyVd+DhbqlTxBPBuXkNURjay2mhq6H6MVVGa+70r2J f0wduSrqgSPQSAwgCannyMnH0CTbfIafnjjtvO1zxH+exdfdVOYM1b32FNM0eVq2BdeU 1uZMyiMAA83YZQ1oAeqte5fPKack5RHL//0h8Mg6kzaHZJKJ0fEHRDjsOWvcA8anIJR+ nz4cjFiHEuv34HfK43C/pWw5gG5Ev55DWyRuDk0qLjJVrV/AX0rmG92rQXBtuE0tqOyp +kKw== X-Gm-Message-State: AIVw113lrxg1ee5p2xsyftDSZg3xITuFSz3k+VXQhUgeYsRDtuEIiz4c m2yTPMRbJ1/Rd3mI X-Received: by 10.25.199.77 with SMTP id x74mr4515810lff.196.1501437186053; Sun, 30 Jul 2017 10:53:06 -0700 (PDT) Original-Received: from [192.168.100.10] (cm-84.210.143.4.getinternet.no. [84.210.143.4]) by smtp.gmail.com with ESMTPSA id m5sm5030493lfm.82.2017.07.30.10.53.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 30 Jul 2017 10:53:05 -0700 (PDT) X-Mailer: geary/0.11.3 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:135164 Archived-At: --=-p4GrjrrZxOwb/2G34Bou Content-Type: text/plain; charset=utf-8; format=flowed Hi. Steve Purcell has developed a very nice major mode for editing Less files (a minor variant of CSS). Seeing that Emacs' built-in CSS mode got extended to support SCSS (another minor CSS variant) three years ago, I contacted Steve and asked if he'd like Less mode to become a part of Emacs as well, which he agreed to. I've attached two patches which merge Steve's Less mode into css-mode.el. The first patch is a verbatim copy of Steve's code, the second one contains minor cleanups made by me. The biggest change I've made is to rename the mode from "Less CSS mode" to just "Less mode". I think the renaming has two advantages: Aligning its name with "SCSS mode", and making the mode's commands, variables and function names shorter. The downside is that existing users of Less mode will have to update their config files. Maybe aliasing `less-css-mode' to `less-mode' could help some in that regard. What do you think of it? If this looks okay, I'll complete the patches (fix the commit messages and make a NEWS entry), install them, and start maintaining Less mode as part of css-mode.el. -- Simen --=-p4GrjrrZxOwb/2G34Bou Content-Type: multipart/mixed; boundary="=-d1bLGzGfoMm57wbQ/H2A" --=-d1bLGzGfoMm57wbQ/H2A Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-WIP-New-major-mode-Less-mode-a-minor-variant-of-CSS.patch >From 343b15f8c95ccbd935b5b715b8127d16bd4d7e84 Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Mon, 12 Jun 2017 22:06:46 +0200 Subject: [PATCH 1/2] WIP: New major mode: Less mode (a minor variant of CSS) --- lisp/textmodes/css-mode.el | 228 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 227 insertions(+), 1 deletion(-) diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el index 19cb7b4fea..c1ed44b984 100644 --- a/lisp/textmodes/css-mode.el +++ b/lisp/textmodes/css-mode.el @@ -32,9 +32,10 @@ ;;; Code: -(require 'eww) (require 'cl-lib) (require 'color) +(require 'compile) +(require 'eww) (require 'seq) (require 'sgml-mode) (require 'smie) @@ -1558,6 +1559,231 @@ scss-mode +;;; Less mode +;; +;; This mode provides syntax highlighting for LESS CSS files, plus +;; optional support for compilation of .less files to .css files at +;; the time they are saved: use `less-css-compile-at-save' to enable +;; this. +;; +;; Command line utility "lessc" is required if setting +;; `less-css-compile-at-save' to t. To install "lessc" using the +;; Node.js package manager, run "npm install less" +;; +;; Also make sure the "lessc" executable is in Emacs' PATH, example: +;; (setq exec-path (cons (expand-file-name "~/.gem/ruby/1.8/bin") exec-path)) +;; or customize `less-css-lessc-command' to point to your "lessc" +;; executable. +;; +;; We target lessc >= 1.4.0, and thus use the `--no-color' flag by +;; default. You may want to adjust `less-css-lessc-options' for +;; compatibility with older versions. +;; +;; `less-css-mode' is derived from `css-mode', and indentation of +;; nested blocks may not work correctly with versions of `css-mode' +;; other than that bundled with recent Emacs. +;; +;; You can specify per-file values for `less-css-compile-at-save', +;; `less-css-output-file-name' or `less-css-output-directory' using a +;; variables header at the top of your .less file, e.g.: +;; +;; // -*- less-css-compile-at-save: t; less-css-output-directory: "../css" -*- +;; +;; Alternatively, you can use directory local variables to set the +;; default value of `less-css-output-directory' for your project. +;; +;; In the case of files which are included in other .less files, you +;; may want to trigger the compilation of a "master" .less file on +;; save: you can accomplish this with `less-css-input-file-name', +;; which is probably best set using directory local variables. +;; +;; If you don't need CSS output but would like to be warned of any +;; syntax errors in your .less source, consider using `flymake-less': +;; https://github.com/purcell/flymake-less +;; +;;; Credits +;; +;; The original code for this mode was, in large part, written using +;; Anton Johansson's scss-mode as a template -- thanks Anton! +;; https://github.com/antonj + +(defgroup less-css nil + "Less-css mode" + :prefix "less-css-" + :group 'css) + +;;;###autoload +(defcustom less-css-lessc-command "lessc" + "Command used to compile LESS files. +Should be lessc or the complete path to your lessc executable, + e.g.: \"~/.gem/ruby/1.8/bin/lessc\"" + :type 'file + :group 'less-css + :safe 'stringp) + +;;;###autoload +(defcustom less-css-compile-at-save nil + "If non-nil, the LESS buffers will be compiled to CSS after each save." + :type 'boolean + :group 'less-css + :safe 'booleanp) + +;;;###autoload +(defcustom less-css-lessc-options '("--no-color") + "Command line options for less executable. + +Use \"-x\" to minify output." + :type '(repeat string) + :group 'less-css + :safe t) + +;;;###autoload +(defcustom less-css-output-directory nil + "Directory in which to save CSS, or nil to use the LESS file's directory. + +This path is expanded relative to the directory of the LESS file +using `expand-file-name', so both relative and absolute paths +will work as expected." + :type 'directory + :group 'less-css + :safe 'stringp) + +;;;###autoload +(defcustom less-css-output-file-name nil + "File name in which to save CSS, or nil to use .css for .less. + +This can be also be set to a full path, or a relative path. If +the path is relative, it will be relative to the value of +`less-css-output-dir', if set, or the current directory by +default." + :type 'file + :group 'less-css + :safe 'stringp) +(make-variable-buffer-local 'less-css-output-file-name) + +;;;###autoload +(defcustom less-css-input-file-name nil + "File name which will be compiled to CSS. + +When the current buffer is saved `less-css-input-file-name' file +will be compiled to css instead of the current file. + +Set this in order to trigger compilation of a \"master\" .less +file which includes the current file. The best way to set this +variable in most cases is likely to be via directory local +variables. + +This can be also be set to a full path, or a relative path. If +the path is relative, it will be relative to the the current directory by +default." + :type 'file + :group 'less-css + :safe 'stringp) +(make-variable-buffer-local 'less-css-input-file-name) + +(defconst less-css-default-error-regex + "^\\(?:\e\\[31m\\)?\\([^\e\n]*\\|FileError:.*\n\\)\\(?:\e\\[39m\e\\[31m\\)? in \\(?:\e\\[39m\\)?\\([^ \r\n\t\e]+\\)\\(?:\e\\[90m\\)?\\(?::\\| on line \\)\\([0-9]+\\)\\(?::\\|, column \\)\\([0-9]+\\):?\\(?:\e\\[39m\\)?") + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Compilation to CSS +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(add-to-list 'compilation-error-regexp-alist-alist + (list 'less-css less-css-default-error-regex 2 3 4 nil 1)) +(add-to-list 'compilation-error-regexp-alist 'less-css) + + +(defun less-css-compile-maybe () + "Run `less-css-compile' if `less-css-compile-at-save' is non-nil." + (if less-css-compile-at-save + (less-css-compile))) + +(defun less-css--output-path () + "Calculate the path for the compiled CSS file created by `less-css-compile'." + (expand-file-name (or less-css-output-file-name + (concat (file-name-nondirectory (file-name-sans-extension buffer-file-name)) ".css")) + (or less-css-output-directory default-directory))) + +(defun less-css--maybe-shell-quote-command (command) + "Selectively shell-quote COMMAND appropriately for `system-type'." + (funcall (if (eq system-type 'windows-nt) + 'identity + 'shell-quote-argument) command)) + +;;;###autoload +(defun less-css-compile () + "Compiles the current buffer to css using `less-css-lessc-command'." + (interactive) + (message "Compiling less to css") + (let ((compilation-buffer-name-function (lambda (mode-name) "*less-css-compilation*"))) + (save-window-excursion + (with-current-buffer + (compile + (mapconcat 'identity + (append (list (less-css--maybe-shell-quote-command less-css-lessc-command)) + (mapcar 'shell-quote-argument less-css-lessc-options) + (list (shell-quote-argument + (or less-css-input-file-name buffer-file-name)) + (shell-quote-argument (less-css--output-path)))) + " ")) + (add-hook 'compilation-finish-functions + (lambda (buf msg) + (unless (string-match-p "^finished" msg) + (display-buffer buf))) + nil + t))))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Minor mode +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; TODO: interpolation ("@{val}"), escaped values (~"..."), JS eval (~`...`), custom faces +(defconst less-css-font-lock-keywords + '(;; Variables + ("@[a-z_-][a-z-_0-9]*" . font-lock-constant-face) + ("&" . font-lock-preprocessor-face) + ;; Mixins + ("\\(?:[ \t{;]\\|^\\)\\(\\.[a-z_-][a-z-_0-9]*\\)[ \t]*;" . (1 font-lock-keyword-face))) + ) + +;;;###autoload +(define-derived-mode less-css-mode css-mode "LESS" + "Major mode for editing LESS files, http://lesscss.org/ +Special commands: +\\{less-css-mode-map}" + (font-lock-add-keywords nil less-css-font-lock-keywords) + ;; cpp-style comments + (modify-syntax-entry ?/ ". 124b" less-css-mode-syntax-table) + (modify-syntax-entry ?* ". 23" less-css-mode-syntax-table) + (modify-syntax-entry ?\n "> b" less-css-mode-syntax-table) + ;; Special chars that sometimes come at the beginning of words. + (modify-syntax-entry ?. "'" less-css-mode-syntax-table) + + (set (make-local-variable 'comment-start) "//") + (set (make-local-variable 'comment-end) "") + (set (make-local-variable 'indent-line-function) 'less-css-indent-line) + (when (functionp 'css-smie-rules) + (smie-setup css-smie-grammar #'css-smie-rules + :forward-token #'css-smie--forward-token + :backward-token #'css-smie--backward-token)) + + (add-hook 'after-save-hook 'less-css-compile-maybe nil t)) + +(define-key less-css-mode-map "\C-c\C-c" 'less-css-compile) + +(defun less-css-indent-line () + "Indent current line according to LESS CSS indentation rules." + (let ((css-navigation-syntax-table less-css-mode-syntax-table)) + (if (fboundp 'css-indent-line) + (css-indent-line) + (smie-indent-line)))) + +;;;###autoload +(add-to-list 'auto-mode-alist '("\\.less\\'" . less-css-mode)) + + + (defvar css--mdn-lookup-history nil) (defcustom css-lookup-url-format -- 2.13.2 --=-d1bLGzGfoMm57wbQ/H2A Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-WIP-Fixes-and-tweaks-for-the-new-Less-mode.patch >From 30d4e2a4b5bb80765e2efa0ef9eba547cc079f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= Date: Mon, 12 Jun 2017 22:15:51 +0200 Subject: [PATCH 2/2] WIP: Fixes and tweaks for the new Less mode --- lisp/textmodes/css-mode.el | 232 +++++++++++++++++++++------------------------ 1 file changed, 109 insertions(+), 123 deletions(-) diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el index c1ed44b984..67b786622b 100644 --- a/lisp/textmodes/css-mode.el +++ b/lisp/textmodes/css-mode.el @@ -1561,41 +1561,42 @@ scss-mode ;;; Less mode ;; +;; Originally authored by Steve Purcell. +;; ;; This mode provides syntax highlighting for LESS CSS files, plus ;; optional support for compilation of .less files to .css files at -;; the time they are saved: use `less-css-compile-at-save' to enable -;; this. +;; the time they are saved: use `less-compile-at-save' to enable this. ;; ;; Command line utility "lessc" is required if setting -;; `less-css-compile-at-save' to t. To install "lessc" using the -;; Node.js package manager, run "npm install less" +;; `less-compile-at-save' to t. To install "lessc" using the Node.js +;; package manager, run "npm install less". ;; ;; Also make sure the "lessc" executable is in Emacs' PATH, example: -;; (setq exec-path (cons (expand-file-name "~/.gem/ruby/1.8/bin") exec-path)) -;; or customize `less-css-lessc-command' to point to your "lessc" -;; executable. +;; (setq exec-path (cons (expand-file-name "~/.gem/ruby/1.8/bin") +;; exec-path)) or customize `less-lessc-command' to point to your +;; "lessc" executable. ;; ;; We target lessc >= 1.4.0, and thus use the `--no-color' flag by -;; default. You may want to adjust `less-css-lessc-options' for +;; default. You may want to adjust `less-lessc-options' for ;; compatibility with older versions. ;; -;; `less-css-mode' is derived from `css-mode', and indentation of -;; nested blocks may not work correctly with versions of `css-mode' -;; other than that bundled with recent Emacs. +;; `less-mode' is derived from `css-mode', and indentation of nested +;; blocks may not work correctly with versions of `css-mode' other +;; than that bundled with recent Emacs. ;; -;; You can specify per-file values for `less-css-compile-at-save', -;; `less-css-output-file-name' or `less-css-output-directory' using a +;; You can specify per-file values for `less-compile-at-save', +;; `less-output-file-name' or `less-output-directory' using a ;; variables header at the top of your .less file, e.g.: ;; -;; // -*- less-css-compile-at-save: t; less-css-output-directory: "../css" -*- +;; // -*- less-compile-at-save: t; less-output-directory: "../css" -*- ;; ;; Alternatively, you can use directory local variables to set the -;; default value of `less-css-output-directory' for your project. +;; default value of `less-output-directory' for your project. ;; ;; In the case of files which are included in other .less files, you ;; may want to trigger the compilation of a "master" .less file on -;; save: you can accomplish this with `less-css-input-file-name', -;; which is probably best set using directory local variables. +;; save: you can accomplish this with `less-input-file-name', which is +;; probably best set using directory local variables. ;; ;; If you don't need CSS output but would like to be warned of any ;; syntax errors in your .less source, consider using `flymake-less': @@ -1607,66 +1608,61 @@ scss-mode ;; Anton Johansson's scss-mode as a template -- thanks Anton! ;; https://github.com/antonj -(defgroup less-css nil - "Less-css mode" - :prefix "less-css-" +(defgroup less nil + "Less CSS mode" + :prefix "less-" :group 'css) ;;;###autoload -(defcustom less-css-lessc-command "lessc" - "Command used to compile LESS files. -Should be lessc or the complete path to your lessc executable, - e.g.: \"~/.gem/ruby/1.8/bin/lessc\"" +(defcustom less-lessc-command "lessc" + "Command used to compile Less files. +Should be \"lessc\" or the complete path to your lessc executable, +e.g.: \"~/.gem/ruby/1.8/bin/lessc\"." :type 'file - :group 'less-css + :group 'less :safe 'stringp) ;;;###autoload -(defcustom less-css-compile-at-save nil - "If non-nil, the LESS buffers will be compiled to CSS after each save." +(defcustom less-compile-at-save nil + "If non-nil, Less buffers are compiled to CSS after each save." :type 'boolean - :group 'less-css + :group 'less :safe 'booleanp) ;;;###autoload -(defcustom less-css-lessc-options '("--no-color") - "Command line options for less executable. - +(defcustom less-lessc-options '("--no-color") + "Command line options for Less executable. Use \"-x\" to minify output." :type '(repeat string) - :group 'less-css + :group 'less :safe t) ;;;###autoload -(defcustom less-css-output-directory nil - "Directory in which to save CSS, or nil to use the LESS file's directory. - -This path is expanded relative to the directory of the LESS file +(defcustom less-output-directory nil + "Directory in which to save CSS, or nil to use the Less file's directory. +This path is expanded relative to the directory of the Less file using `expand-file-name', so both relative and absolute paths will work as expected." :type 'directory - :group 'less-css + :group 'less :safe 'stringp) ;;;###autoload -(defcustom less-css-output-file-name nil +(defcustom less-output-file-name nil "File name in which to save CSS, or nil to use .css for .less. - This can be also be set to a full path, or a relative path. If the path is relative, it will be relative to the value of -`less-css-output-dir', if set, or the current directory by -default." +`less-output-dir', if set, or the current directory by default." :type 'file - :group 'less-css + :group 'less :safe 'stringp) -(make-variable-buffer-local 'less-css-output-file-name) +(make-variable-buffer-local 'less-output-file-name) ;;;###autoload -(defcustom less-css-input-file-name nil +(defcustom less-input-file-name nil "File name which will be compiled to CSS. - -When the current buffer is saved `less-css-input-file-name' file -will be compiled to css instead of the current file. +When the current buffer is saved `less-input-file-name' file will +be compiled to CSS instead of the current file. Set this in order to trigger compilation of a \"master\" .less file which includes the current file. The best way to set this @@ -1674,59 +1670,61 @@ less-css-input-file-name variables. This can be also be set to a full path, or a relative path. If -the path is relative, it will be relative to the the current directory by -default." +the path is relative, it will be relative to the the current +directory by default." :type 'file - :group 'less-css + :group 'less :safe 'stringp) -(make-variable-buffer-local 'less-css-input-file-name) +(make-variable-buffer-local 'less-input-file-name) -(defconst less-css-default-error-regex +(defconst less-default-error-regex "^\\(?:\e\\[31m\\)?\\([^\e\n]*\\|FileError:.*\n\\)\\(?:\e\\[39m\e\\[31m\\)? in \\(?:\e\\[39m\\)?\\([^ \r\n\t\e]+\\)\\(?:\e\\[90m\\)?\\(?::\\| on line \\)\\([0-9]+\\)\\(?::\\|, column \\)\\([0-9]+\\):?\\(?:\e\\[39m\\)?") - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Compilation to CSS -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (add-to-list 'compilation-error-regexp-alist-alist - (list 'less-css less-css-default-error-regex 2 3 4 nil 1)) -(add-to-list 'compilation-error-regexp-alist 'less-css) - - -(defun less-css-compile-maybe () - "Run `less-css-compile' if `less-css-compile-at-save' is non-nil." - (if less-css-compile-at-save - (less-css-compile))) - -(defun less-css--output-path () - "Calculate the path for the compiled CSS file created by `less-css-compile'." - (expand-file-name (or less-css-output-file-name - (concat (file-name-nondirectory (file-name-sans-extension buffer-file-name)) ".css")) - (or less-css-output-directory default-directory))) - -(defun less-css--maybe-shell-quote-command (command) + (list 'less less-default-error-regex 2 3 4 nil 1)) +(add-to-list 'compilation-error-regexp-alist 'less) + +(defun less-compile-maybe () + "Run `less-compile' if `less-compile-at-save' is non-nil." + (when less-compile-at-save + (less-compile))) + +(defun less--output-path () + "Return the path to use for the compiled CSS file." + (expand-file-name + (or less-output-file-name + (concat + (file-name-nondirectory + (file-name-sans-extension buffer-file-name)) + ".css")) + (or less-output-directory default-directory))) + +(defun less--maybe-shell-quote-command (command) "Selectively shell-quote COMMAND appropriately for `system-type'." (funcall (if (eq system-type 'windows-nt) 'identity - 'shell-quote-argument) command)) + 'shell-quote-argument) + command)) ;;;###autoload -(defun less-css-compile () - "Compiles the current buffer to css using `less-css-lessc-command'." +(defun less-compile () + "Compile the current buffer to CSS using `less-lessc-command'." (interactive) - (message "Compiling less to css") - (let ((compilation-buffer-name-function (lambda (mode-name) "*less-css-compilation*"))) + (message "Compiling Less to CSS") + (let ((compilation-buffer-name-function + (lambda (_) "*less-compilation*"))) (save-window-excursion (with-current-buffer (compile - (mapconcat 'identity - (append (list (less-css--maybe-shell-quote-command less-css-lessc-command)) - (mapcar 'shell-quote-argument less-css-lessc-options) - (list (shell-quote-argument - (or less-css-input-file-name buffer-file-name)) - (shell-quote-argument (less-css--output-path)))) - " ")) + (string-join + (append (list (less--maybe-shell-quote-command less-lessc-command)) + (mapcar 'shell-quote-argument less-lessc-options) + (list (shell-quote-argument + (or less-input-file-name buffer-file-name)) + (shell-quote-argument (less--output-path)))) + " ")) (add-hook 'compilation-finish-functions (lambda (buf msg) (unless (string-match-p "^finished" msg) @@ -1734,53 +1732,41 @@ less-css-compile nil t))))) -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Minor mode -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;; TODO: interpolation ("@{val}"), escaped values (~"..."), JS eval (~`...`), custom faces -(defconst less-css-font-lock-keywords +;; TODO: +;; - interpolation ("@{val}") +;; - escaped values (~"...") +;; - JavaScript eval (~`...`) +;; - custom faces +(defconst less-font-lock-keywords '(;; Variables - ("@[a-z_-][a-z-_0-9]*" . font-lock-constant-face) + ("@[a-z_-][a-z-_0-9]*" . font-lock-variable-name-face) ("&" . font-lock-preprocessor-face) ;; Mixins - ("\\(?:[ \t{;]\\|^\\)\\(\\.[a-z_-][a-z-_0-9]*\\)[ \t]*;" . (1 font-lock-keyword-face))) - ) + ("\\(?:[ \t{;]\\|^\\)\\(\\.[a-z_-][a-z-_0-9]*\\)[ \t]*;" . + (1 font-lock-keyword-face)))) + +(defvar less-mode-syntax-table + (let ((st (make-syntax-table css-mode-syntax-table))) + ;; C++-style comments. + (modify-syntax-entry ?/ ". 124b" st) + (modify-syntax-entry ?* ". 23" st) + (modify-syntax-entry ?\n "> b" st) + ;; Special chars that sometimes come at the beginning of words. + (modify-syntax-entry ?. "'" st) + st)) +;;;###autoload (add-to-list 'auto-mode-alist '("\\.less\\'" . less-mode)) ;;;###autoload -(define-derived-mode less-css-mode css-mode "LESS" - "Major mode for editing LESS files, http://lesscss.org/ +(define-derived-mode less-mode css-mode "Less" + "Major mode for editing Less files, http://lesscss.org/ Special commands: -\\{less-css-mode-map}" - (font-lock-add-keywords nil less-css-font-lock-keywords) - ;; cpp-style comments - (modify-syntax-entry ?/ ". 124b" less-css-mode-syntax-table) - (modify-syntax-entry ?* ". 23" less-css-mode-syntax-table) - (modify-syntax-entry ?\n "> b" less-css-mode-syntax-table) - ;; Special chars that sometimes come at the beginning of words. - (modify-syntax-entry ?. "'" less-css-mode-syntax-table) - - (set (make-local-variable 'comment-start) "//") - (set (make-local-variable 'comment-end) "") - (set (make-local-variable 'indent-line-function) 'less-css-indent-line) - (when (functionp 'css-smie-rules) - (smie-setup css-smie-grammar #'css-smie-rules - :forward-token #'css-smie--forward-token - :backward-token #'css-smie--backward-token)) - - (add-hook 'after-save-hook 'less-css-compile-maybe nil t)) - -(define-key less-css-mode-map "\C-c\C-c" 'less-css-compile) - -(defun less-css-indent-line () - "Indent current line according to LESS CSS indentation rules." - (let ((css-navigation-syntax-table less-css-mode-syntax-table)) - (if (fboundp 'css-indent-line) - (css-indent-line) - (smie-indent-line)))) +\\{less-mode-map}" + (font-lock-add-keywords nil less-font-lock-keywords) + (setq-local comment-start "//") + (setq-local comment-end "") + (add-hook 'after-save-hook 'less-compile-maybe nil t)) -;;;###autoload -(add-to-list 'auto-mode-alist '("\\.less\\'" . less-css-mode)) +(define-key less-mode-map "\C-c\C-c" 'less-compile) -- 2.13.2 --=-d1bLGzGfoMm57wbQ/H2A-- --=-p4GrjrrZxOwb/2G34Bou--