]> code.delx.au - gnu-emacs-elpa/blob - packages/nameless/README.org
Merge commit 'ea3958f45cb468be0f11e95c24d09e10a389fee0'
[gnu-emacs-elpa] / packages / nameless / README.org
1 #+OPTIONS: toc:nil num:nil
2
3 * Nameless --- /less is more/
4 *Hide package namespaces in your emacs-lisp code.*
5
6 Simply put, turn on this minor mode, and the namespace prefix of the
7 package you’re editing will be hidden by a ~:~. Here’s a comparison.
8 The image to the *left* is what you normally see. The image to
9 the *right* has ~nameless-mode~ turned on.\\
10 [[file:example-nameless.png]]
11
12 ** Usage
13
14 To use this package add the following configuration to your Emacs init file.
15
16 #+BEGIN_SRC emacs-lisp
17 (add-hook 'emacs-lisp-mode-hook #'nameless-mode-from-hook)
18 #+END_SRC
19
20 You can configure a string to use instead of ~:~ by setting the
21 ~nameless-prefix~, and the name of the face used is ~nameless-face~.
22 You can even just hide the prefix completely by setting this variable
23 to an empty string.
24
25 While the mode is active, the =C-c C--= key inserts the
26 package namespace if appropriate.
27
28 * Configuration
29
30 ** Quickly typing the namespace
31 ~nameless-mode~ binds the =C-c C--= key to
32 ~nameless-insert-name~, which immediately inserts the current name for
33 you, or even expands aliases to the names they point to.
34
35 Let’s say you’re in a file called ~foo-bar.el~.
36 #+BEGIN_SRC text
37 C-c C-- → foo-bar-
38 fl C-c C-- → font-lock-
39 #+END_SRC
40
41 There’s also a command called ~nameless-insert-name-or-self-insert~.
42 You can bind this to the =_= key and make it even faster to
43 insert the name.
44 ** Configuring the namespace name
45 Nameless guesses the package name with the ~lm-get-package-name~
46 function, but sometimes this might not match the name you want to use.
47
48 In these situations, simply set ~nameless-current-name~ as file-local variable.
49 To do that, invoke the following command:
50 #+BEGIN_SRC text
51 M-x add-file-local-variable RET nameless-current-name RET "package-name"
52 #+END_SRC
53 You can also set the same name for all lisp files in a project by
54 setting dir-local variables with ~M-x add-file-local-variable~.
55
56 ** Requiring other packages as aliases
57 Nameless can also be used to “import” other packages as aliases. For
58 instance, in the default behaviour, functions in the ~font-lock~
59 package (e.g., ~font-lock-add-keywords~) will be displayed with the
60 ~fl:~ prefix (e.g., ~fl:add-keywords~).
61
62 You can configure your own aliases globally with ~nameless-global-aliases~.
63 #+BEGIN_SRC emacs-lisp
64 (setq nameless-global-aliases '(("fl" . "font-lock")
65 ("s" . "seq")
66 ("me" . "macroexp")
67 ("c" . "cider")
68 ("q" . "queue")))
69 #+END_SRC
70
71 You can also configure aliases per-file by setting ~nameless-aliases~
72 as a file-local variable.
73 #+BEGIN_SRC emacs-lisp
74 ;; Local Variables:
75 ;; nameless-aliases: (("c" . "cider"))
76 ;; End:
77 #+END_SRC
78 Note that there’s no ~quote~ before ~((c~!\\
79 You can also configure it for a whole project, by setting it as a dir-local variable.
80
81 ** Indentation and paragraph filling
82 Hiding parts of symbols could affect the way Emacs indents your code
83 and fills your paragraphs. Nameless lets you decide whether you want
84 that to happen or not.
85
86 The default behavior is that code is indented according to what you
87 see (i.e., according to short symbols), but text inside strings is
88 *not*. So text inside strings will be filled in the same way as if you
89 didn’t have ~nameless-mode~. Here’s how a docstring might be filled
90 with ~nameless-mode~ enabled:
91 #+BEGIN_SRC text
92 If point is immediately after an alias configured in the name you
93 had in `:aliases' or `:global-aliases', replace
94 it with the full name for that alias.
95 #+END_SRC
96 Altough it may look strange that the second line is so short, that’s
97 the correct way. When view on a ~*Help*~ buffer, that docstring will
98 look like this:
99 #+BEGIN_SRC text
100 If point is immediately after an alias configured in the name you
101 had in `nameless-aliases' or `nameless-global-aliases', replace
102 it with the full name for that alias.
103 #+END_SRC
104
105 To change this behavior, configure the variable
106 ~nameless-affect-indentation-and-filling~.