]> code.delx.au - gnu-emacs-elpa/blob - packages/nameless/README.org
Merge commit 'd16c20ffc2197234d4dd631fd66768c3a4b305c9'
[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 ** Private symbols
82
83 Private symbols in elisp are written with an extra dash after the
84 prefix (e.g., ~foobar--indent-impl~). With Nameless, these are usually
85 displayed as ~:-indent-impl~, but you can also make them be displayed
86 as ~::indent-impl~ by setting
87
88 #+BEGIN_SRC emacs-lisp
89 (setq nameless-private-prefix t)
90 #+END_SRC
91
92 ** Indentation and paragraph filling
93 Hiding parts of symbols could affect the way Emacs indents your code
94 and fills your paragraphs. Nameless lets you decide whether you want
95 that to happen or not.
96
97 The default behavior is that code is indented according to what you
98 see (i.e., according to short symbols), but text inside strings is
99 *not*. So text inside strings will be filled in the same way as if you
100 didn’t have ~nameless-mode~. Here’s how a docstring might be filled
101 with ~nameless-mode~ enabled:
102 #+BEGIN_SRC text
103 If point is immediately after an alias configured in the name you
104 had in `:aliases' or `:global-aliases', replace
105 it with the full name for that alias.
106 #+END_SRC
107 Altough it may look strange that the second line is so short, that’s
108 the correct way. When view on a ~*Help*~ buffer, that docstring will
109 look like this:
110 #+BEGIN_SRC text
111 If point is immediately after an alias configured in the name you
112 had in `nameless-aliases' or `nameless-global-aliases', replace
113 it with the full name for that alias.
114 #+END_SRC
115
116 To change this behavior, configure the variable
117 ~nameless-affect-indentation-and-filling~.