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)
+ (add-hook 'emacs-lisp-mode-hook #'nameless-mode-from-hook)
#+END_SRC
You can configure a string to use instead of ~:~ by setting the
You can even just hide the prefix completely by setting this variable
to an empty string.
- While the mode is active, the =_= key inserts the package namespace if
- appropriate.
+ While the mode is active, the <kbd>C-c C--</kbd> key inserts the
+ package namespace if appropriate.
* Configuration
+ ** Quickly typing the namespace
+ ~nameless-mode~ binds the <kbd>C-c C--</kbd> key to
+ ~nameless-insert-name~, which immediately inserts the current name for
+ you, or even expands aliases to the names they point to.
+
+ Let’s say you’re in a file called ~foo-bar.el~.
+ #+BEGIN_SRC text
+ C-c C-- → foo-bar-
+ fl C-c C-- → font-lock-
+ #+END_SRC
+
+ There’s also a command called ~nameless-insert-name-or-self-insert~.
+ You can bind this to the <kbd>_</kbd> key and make it even faster to
+ insert the name.
+ ** Configuring the namespace name
+ Nameless guesses the package name with the ~lm-get-package-name~
+ function, but sometimes this might not match the name you want to use.
+
+ In these situations, simply set ~nameless-current-name~ as file-local variable.
+ To do that, invoke the following command:
+ #+BEGIN_SRC text
+ M-x add-file-local-variable RET nameless-current-name RET "package-name"
+ #+END_SRC
+ You can also set the same name for all lisp files in a project by
+ setting dir-local variables with ~M-x add-file-local-variable~.
+
+ ** Requiring other packages as aliases
Nameless can also be used to “import” other packages as aliases. For
instance, in the default behaviour, functions in the ~font-lock~
package (e.g., ~font-lock-add-keywords~) will be displayed with the
~fl:~ prefix (e.g., ~fl:add-keywords~).
- You can configure your own aliases globally with
- ~nameless-global-aliases~, and on a file-local basis with
- ~nameless-aliases~.
+ You can configure your own aliases globally with ~nameless-global-aliases~.
+ #+BEGIN_SRC emacs-lisp
+ (setq nameless-global-aliases '(("fl" . "font-lock")
+ ("s" . "seq")
+ ("me" . "macroexp")
+ ("c" . "cider")
+ ("q" . "queue")))
+ #+END_SRC
+
+ You can also configure aliases per-file by setting ~nameless-aliases~
+ as a file-local variable.
+ #+BEGIN_SRC emacs-lisp
+ ;; Local Variables:
+ ;; nameless-aliases: (("c" . "cider"))
+ ;; End:
+ #+END_SRC
+ /Note that there’s no ~quote~ before ~((c~!/\\
+ You can also configure it for a whole project, by setting it as a dir-local variable.
+
+ ** Indentation and paragraph filling
+ Hiding parts of symbols could affect the way Emacs indents your code
+ and fills your paragraphs. Nameless lets you decide whether you want
+ that to happen or not.
+
+ The default behavior is that code is indented according to what you
+ see (i.e., according to short symbols), but text inside strings is
+ *not*. So text inside strings will be filled in the same way as if you
+ didn’t have ~nameless-mode~. Here’s how a docstring might be filled
+ with ~nameless-mode~ enabled:
+ #+BEGIN_SRC text
+ If point is immediately after an alias configured in the name you
+ had in `:aliases' or `:global-aliases', replace
+ it with the full name for that alias.
+ #+END_SRC
+ Altough it may look strange that the second line is so short, that’s
+ the correct way. When view on a ~*Help*~ buffer, that docstring will
+ look like this:
+ #+BEGIN_SRC text
+ If point is immediately after an alias configured in the name you
+ had in `nameless-aliases' or `nameless-global-aliases', replace
+ it with the full name for that alias.
+ #+END_SRC
+
+ To change this behavior, configure the variable
+ ~nameless-affect-indentation-and-filling~.
;; Author: Artur Malabarba <emacs@endlessparentheses.com>
;; Keywords: convenience, lisp
- ;; Version: 0.3.1
+ ;; Version: 0.4
;; Package-Requires: ((emacs "24.4"))
;; This program is free software; you can redistribute it and/or modify
those in `nameless-global-aliases'.
This variable is designed to be used as a file-local or dir-local
variable.")
+ (put 'nameless-aliases 'safe-local-variable
+ (lambda (x) (ignore-errors
+ (let ((safe t))
+ (mapc (lambda (cell)
+ (unless (and (stringp (car cell))
+ (stringp (cdr cell)))
+ (setq safe nil)))
+ x)
+ safe))))
(defface nameless-face
'((t :inherit font-lock-type-face))
(defvar nameless-mode)
(defun nameless--compose-as (display)
"Compose the matched region and return a face spec."
- (when nameless-mode
+ (when (and nameless-mode
+ (not (get-text-property (match-beginning 1) 'composition))
+ (not (get-text-property (match-beginning 1) 'display)))
(let ((compose (save-match-data
(and nameless-affect-indentation-and-filling
- (or (not (eq nameless-affect-indentation-and-filling 'outside-strings))
- (not (nth 3 (syntax-ppss)))))))
+ (or (not (eq nameless-affect-indentation-and-filling 'outside-strings))
+ (not (nth 3 (syntax-ppss)))))))
(dis (concat display nameless-prefix)))
(when compose
(compose-region (match-beginning 1)
\(fn (regexp . display) [(regexp . display) ...])"
(setq-local font-lock-extra-managed-props
`(composition display ,@font-lock-extra-managed-props))
- (let ((kws (mapcar (lambda (x) `(,(nameless--name-regexp (cdr x)) 1 (nameless--compose-as ,(car x)) prepend)) r)))
+ (let ((kws (mapcar (lambda (x) `(,(nameless--name-regexp (cdr x)) 1 (nameless--compose-as ,(car x)))) r)))
(setq nameless--font-lock-keywords kws)
(font-lock-add-keywords nil kws t))
(nameless--ensure))
\f
;;; Name and regexp
(defvar-local nameless-current-name nil)
+ (put 'nameless-current-name 'safe-local-variable #'stringp)
(defun nameless--in-arglist-p ()
"Is point inside an arglist?"
(assoc alias nameless-global-aliases))))))
(if full-name
(progn (delete-region l r)
- (insert full-name "-"))
+ (insert full-name "-")
+ t)
(unless noerror
(user-error "No name for alias `%s', see `nameless-aliases'" alias))))
(if nameless-current-name
(or (nameless-insert-name 'noerror)
(call-interactively #'self-insert-command))))
+ (put 'nameless-insert-name-or-self-insert 'delete-selection t)
+
(defun nameless--name-regexp (name)
"Return a regexp of the current name."
(concat "\\_<@?\\(" (regexp-quote name) "-\\)\\(\\s_\\|\\sw\\)"))
;;; Minor mode
;;;###autoload
(define-minor-mode nameless-mode
- nil nil " :" '(("_" . nameless-insert-name-or-self-insert))
+ nil nil " :" `((,(kbd "C-c C--") . nameless-insert-name))
(if nameless-mode
(if (or nameless-current-name
(ignore-errors (string-match "\\.el\\'" (lm-get-package-name))))
(setq nameless-current-name nil)
(nameless--remove-keywords)))
+ ;;;###autoload
+ (defun nameless-mode-from-hook ()
+ "Turn on `nameless-mode'.
+ Designed to be added to `emacs-lisp-mode-hook'.
+ Interactively, just invoke `nameless-mode' directly."
+ (add-hook 'find-file-hook #'nameless-mode nil 'local))
+
(provide 'nameless)
;;; nameless.el ends here