From: Artur Malabarba Date: Wed, 9 Sep 2015 11:07:52 +0000 (+0100) Subject: Merge commit '60873230991f7a0cd3175eb578fee34c7e238fb3' X-Git-Url: https://code.delx.au/gnu-emacs-elpa/commitdiff_plain/8ad76a71b3023cf715c6dbc25cfa64468174c6b7?hp=a1c9e99bb40cec84026ee23e368458ae9a0852bd Merge commit '60873230991f7a0cd3175eb578fee34c7e238fb3' --- diff --git a/packages/nameless/README.org b/packages/nameless/README.org index 12d5fe5c7..75f8835d1 100644 --- a/packages/nameless/README.org +++ b/packages/nameless/README.org @@ -14,7 +14,7 @@ the *right* has ~nameless-mode~ turned on.\\ 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 @@ -22,16 +22,85 @@ 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 C-c C-- key inserts the +package namespace if appropriate. * Configuration +** Quickly typing the namespace +~nameless-mode~ binds the C-c C-- 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 _ 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~. diff --git a/packages/nameless/nameless.el b/packages/nameless/nameless.el index 6737aa0fc..a0d517738 100644 --- a/packages/nameless/nameless.el +++ b/packages/nameless/nameless.el @@ -4,7 +4,7 @@ ;; Author: Artur Malabarba ;; 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 @@ -72,6 +72,15 @@ This variable takes the same syntax and has the same effect as 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)) @@ -98,11 +107,13 @@ for it to take effect." (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) @@ -128,7 +139,7 @@ for it to take effect." \(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)) @@ -136,6 +147,7 @@ for it to take effect." ;;; 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?" @@ -171,7 +183,8 @@ configured, or if `nameless-current-name' is nil." (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 @@ -191,6 +204,8 @@ configured, or if `nameless-current-name' is nil." (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\\)")) @@ -206,7 +221,7 @@ Return S." ;;; 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)))) @@ -225,5 +240,12 @@ Return S." (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