[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 1a1719a 02/15: Add file
From: |
Artur Malabarba |
Subject: |
[elpa] master 1a1719a 02/15: Add file |
Date: |
Thu, 03 Sep 2015 11:01:18 +0000 |
branch: master
commit 1a1719a5310d482b5d779d3f86c036298135fee1
Author: Artur Malabarba <address@hidden>
Commit: Artur Malabarba <address@hidden>
Add file
---
README.md | 2 -
README.org | 23 ++++++++
example-nameless-off.png | Bin 0 -> 33500 bytes
example-nameless-on.png | Bin 0 -> 26527 bytes
nameless.el | 128 ++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 151 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
deleted file mode 100644
index e0f7c6d..0000000
--- a/README.md
+++ /dev/null
@@ -1,2 +0,0 @@
-# Nameless
-Hide package namespace in your emacs-lisp code
diff --git a/README.org b/README.org
new file mode 100644
index 0000000..2422958
--- /dev/null
+++ b/README.org
@@ -0,0 +1,23 @@
+#+OPTIONS: toc:nil num:nil
+
+* Nameless
+Hide package namespace in your emacs-lisp code.
+
+Simply put, turn on this minor mode, and you’ll see this
+[[file:example-nameless-on.png]]\\
+instead of this
+[[file:example-nameless-off.png]]
+
+** Usage
+
+To use this package add the following configuration to your Emacs init file.
+
+#+BEGIN_SRC emacs-lisp
+(add-hook 'emacs-lisp-mode-hook #'nameless-mode)
+#+END_SRC
+
+You can configure a string to use instead of ~:~ by setting the
~nameless-prefix~,
+and the name of the face used is ~nameless-face~.
+
+While the mode is active, the =:= and =_= keys will insert the package
+namespace when appropriate.
diff --git a/example-nameless-off.png b/example-nameless-off.png
new file mode 100644
index 0000000..a4bbcda
Binary files /dev/null and b/example-nameless-off.png differ
diff --git a/example-nameless-on.png b/example-nameless-on.png
new file mode 100644
index 0000000..e79cc3a
Binary files /dev/null and b/example-nameless-on.png differ
diff --git a/nameless.el b/nameless.el
new file mode 100644
index 0000000..91dde56
--- /dev/null
+++ b/nameless.el
@@ -0,0 +1,128 @@
+;;; nameless.el --- Hide package namespace in your emacs-lisp code -*-
lexical-binding: t; -*-
+
+;; Copyright (C) 2015 Free Software Foundation, Inc.
+
+;; Author: Artur Malabarba <address@hidden>
+;; Keywords: convenience, lisp
+;; Version: 0.1
+;; Package-Requires: ((emacs "24.3"))
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Usage
+;; ─────
+;;
+;; To use this package add the following configuration to your Emacs init
+;; file.
+;;
+;; ┌────
+;; │ (add-hook 'emacs-lisp-mode-hook #'nameless-mode)
+;; └────
+;;
+;; You can configure a string to use instead of `:' by setting the
+;; `nameless-prefix', and the name of the face used is `nameless-face'.
+;;
+;; While the mode is active, the `:' and `_' keys will insert the package
+;; namespace when appropriate.
+
+;;; Code:
+(require 'lisp-mnt)
+
+(defgroup nameless nil
+ "Customization group for nameless."
+ :group 'emacs)
+
+(defcustom nameless-prefix ":"
+ "Prefix displayed instead of package namespace."
+ :type 'string)
+
+(defface nameless-face
+ '((t :inherit font-lock-keyword-face))
+ "Face used on `nameless-prefix'")
+
+
+;;; Font-locking
+(defvar nameless-mode)
+(defun nameless--compose-as (display)
+ "Compose the matched region and return a face spec."
+ (when nameless-mode
+ (compose-region (match-beginning 0)
+ (match-end 0)
+ (or display nameless-prefix))
+ '(face nameless-face)))
+
+(defun nameless--add-keywords (&rest r)
+ "Add font-lock keywords displaying REGEXP as DISPLAY.
+
+\(fn regexp display [regexp display ...])"
+ (setq-local font-lock-extra-managed-props
+ (cons 'composition font-lock-extra-managed-props))
+ (while r
+ (font-lock-add-keywords
+ nil `((,(pop r) 0 (nameless--compose-as ,(pop r)) prepend)) t))
+ (with-no-warnings
+ (if (fboundp 'font-lock-ensure)
+ (font-lock-ensure)
+ (font-lock-fontify-buffer))))
+
+
+;;; Name and regexp
+(defvar-local nameless-current-name-regexp nil)
+(defvar-local nameless-current-name nil)
+
+(defun nameless--in-arglist-p ()
+ "Is point inside an arglist?"
+ (save-excursion
+ (ignore-errors
+ (backward-up-list)
+ (forward-sexp -2)
+ (looking-at-p "def\\(un\\|macro\\)\\_>"))))
+
+(defun nameless-insert-name (&optional self-insert)
+ "Insert the name of current package, with a hyphen."
+ (interactive "P")
+ (if (or self-insert
+ (not nameless-current-name)
+ (nameless--in-arglist-p)
+ (string-match (rx (or (syntax symbol)
+ (syntax word)))
+ (string (char-before))))
+ (call-interactively #'self-insert-command)
+ (insert nameless-current-name "-")))
+
+(defun nameless--name-regexp (name)
+ "Return a regexp of the current name."
+ (concat "\\<" (regexp-quote name) "-"))
+
+
+;;; Minor mode
+(define-minor-mode nameless-mode
+ nil nil " :" '(("_" . nameless-insert-name))
+ (if (and nameless-mode)
+ (if (or nameless-current-name-regexp
+ nameless-current-name
+ (ignore-errors (string-match "\\.el\\'" (lm-get-package-name))))
+ (progn
+ (unless nameless-current-name-regexp
+ (unless nameless-current-name
+ (setq nameless-current-name (replace-regexp-in-string
"\\.[^.]*\\'" "" (lm-get-package-name))))
+ (setq nameless-current-name-regexp (nameless--name-regexp
nameless-current-name)))
+ (nameless--add-keywords nameless-current-name-regexp))
+ (nameless-mode -1))))
+;; (font-lock-remove-keywords)
+
+(provide 'nameless)
+;;; nameless.el ends here
- [elpa] master updated (4de2352 -> e0a3544), Artur Malabarba, 2015/09/03
- [elpa] master dc2fb41 06/15: Improve regexps, Artur Malabarba, 2015/09/03
- [elpa] master 3074f24 01/15: Initial commit, Artur Malabarba, 2015/09/03
- [elpa] master f662c5e 10/15: Fix composition, Artur Malabarba, 2015/09/03
- [elpa] master 2cd0e01 03/15: Autoload, Artur Malabarba, 2015/09/03
- [elpa] master 1a1719a 02/15: Add file,
Artur Malabarba <=
- [elpa] master 7c425ed 12/15: Documentation, Artur Malabarba, 2015/09/03
- [elpa] master e23d22c 04/15: Implement disabling the mode too, Artur Malabarba, 2015/09/03
- [elpa] master e8922a6 05/15: Only hide prefix if something is written after it, Artur Malabarba, 2015/09/03
- [elpa] master 3690ce8 13/15: Add nameless-insert-name-or-self-insert command, Artur Malabarba, 2015/09/03
- [elpa] master b81dadf 08/15: Add nameless-affect-indentation variable, to decide between display and compose, Artur Malabarba, 2015/09/03
- [elpa] master 59d6da9 07/15: Change defaults a bit, Artur Malabarba, 2015/09/03
- [elpa] master 1937b95 09/15: Implement aliases, Artur Malabarba, 2015/09/03
- [elpa] master c1dd76b 14/15: Readme, Artur Malabarba, 2015/09/03
- [elpa] master 9767c97 11/15: Improve aliases, Artur Malabarba, 2015/09/03
- [elpa] master e0a3544 15/15: Add 'packages/nameless/' from commit 'c1dd76b972ab978884d5c1b2add43e83cc23134e', Artur Malabarba, 2015/09/03