diff options
| author | Stefan Kangas | 2022-12-09 06:30:26 +0100 |
|---|---|---|
| committer | Stefan Kangas | 2022-12-09 06:30:26 +0100 |
| commit | 3db9a0d0408ef0b2c63fec0c2666b4812e4ceeec (patch) | |
| tree | 193e951bc58abd7135d04235b0c1fc25cb9032fb | |
| parent | 2f0bd8167c015bab729b998daa1e77d24d54ced4 (diff) | |
| parent | 5b640f0abd3f83449e8780ce8060eb723574986b (diff) | |
| download | emacs-3db9a0d0408ef0b2c63fec0c2666b4812e4ceeec.tar.gz emacs-3db9a0d0408ef0b2c63fec0c2666b4812e4ceeec.zip | |
Merge from origin/emacs-29
5b640f0abd3 Improve :delight keyword example in use-package manual
c417fe4df3b ; Refer to the manual in use-package docstring
0b3116971af Clarify :after keyword in use-package docstring
a17a6036dd4 Add conditional loading examples to use-package manual
| -rw-r--r-- | doc/misc/use-package.texi | 93 | ||||
| -rw-r--r-- | lisp/use-package/use-package-core.el | 13 |
2 files changed, 84 insertions, 22 deletions
diff --git a/doc/misc/use-package.texi b/doc/misc/use-package.texi index 2e1747fa78d..4f0f8a26773 100644 --- a/doc/misc/use-package.texi +++ b/doc/misc/use-package.texi | |||
| @@ -394,21 +394,60 @@ is provided as an alias for @code{:if}. Finally, the @code{:unless} | |||
| 394 | keyword is the inverse of @code{:if}, such that @w{@code{:unless foo}} | 394 | keyword is the inverse of @code{:if}, such that @w{@code{:unless foo}} |
| 395 | means the same thing as @w{@code{:if (not foo)}}. | 395 | means the same thing as @w{@code{:if (not foo)}}. |
| 396 | 396 | ||
| 397 | For example, if you only want @samp{foo} in graphical Emacs sessions, | 397 | For example, if you only want to load @samp{foo} in graphical Emacs |
| 398 | you could use the following: | 398 | sessions, you could use the following: |
| 399 | 399 | ||
| 400 | @lisp | 400 | @lisp |
| 401 | (use-package foo | 401 | (use-package foo |
| 402 | :if (display-graphic-p)) | 402 | :if (display-graphic-p)) |
| 403 | @end lisp | 403 | @end lisp |
| 404 | 404 | ||
| 405 | Another common use case is to make it conditional on the operating | 405 | @subheading Some common use cases |
| 406 | system: | 406 | |
| 407 | Here are some common cases for conditional loading, and how to achieve | ||
| 408 | them. | ||
| 409 | |||
| 410 | @itemize | ||
| 411 | |||
| 412 | @item Operating system | ||
| 413 | |||
| 414 | This example loads a package only on GNU/Linux. See the | ||
| 415 | @code{system-type} docstring for other valid values. | ||
| 407 | 416 | ||
| 408 | @lisp | 417 | @lisp |
| 409 | (use-package foo | 418 | :if (eq system-type 'gnu/linux) |
| 410 | :if (memq window-system '(mac ns))) | 419 | @end lisp |
| 420 | |||
| 421 | @item Window system | ||
| 422 | |||
| 423 | This example loads a package only on macOS and X. See the | ||
| 424 | @code{window-system} docstring for valid values. | ||
| 425 | |||
| 426 | @lisp | ||
| 427 | :if (memq window-system '(ns x)) | ||
| 428 | @end lisp | ||
| 429 | |||
| 430 | @item Installed package | ||
| 431 | |||
| 432 | This example loads a package only when the @samp{foo} package is | ||
| 433 | installed. | ||
| 434 | |||
| 435 | @lisp | ||
| 436 | :if (package-installed-p 'foo) | ||
| 437 | @end lisp | ||
| 438 | |||
| 439 | @item Libraries in @code{load-path} | ||
| 440 | |||
| 441 | This example loads a package only when @file{foo.el} is available in | ||
| 442 | your @code{load-path} (for example, if you installed that file | ||
| 443 | manually): | ||
| 444 | |||
| 445 | @lisp | ||
| 446 | :if (locate-library "foo.el") | ||
| 411 | @end lisp | 447 | @end lisp |
| 448 | @end itemize | ||
| 449 | |||
| 450 | @subheading Making conditional loading affect @code{:preface} and @code{:ensure} | ||
| 412 | 451 | ||
| 413 | @cindex conditional loading before @code{:preface} or @code{:ensure} | 452 | @cindex conditional loading before @code{:preface} or @code{:ensure} |
| 414 | If you need to conditionalize a use-package form so that the condition | 453 | If you need to conditionalize a use-package form so that the condition |
| @@ -1204,10 +1243,12 @@ install the corresponding package from @acronym{GNU ELPA}. | |||
| 1204 | @findex :diminish | 1243 | @findex :diminish |
| 1205 | When diminish@footnote{The diminish package is installable from | 1244 | When diminish@footnote{The diminish package is installable from |
| 1206 | @acronym{GNU ELPA}.} is installed, you can use the @code{:diminish} | 1245 | @acronym{GNU ELPA}.} is installed, you can use the @code{:diminish} |
| 1207 | keyword. First, add the following declaration to the beginning of | 1246 | keyword. If diminish is not installed, the @code{:diminish} keyword |
| 1208 | your init file. The optional @w{@code{:ensure t}} makes sure the | 1247 | does nothing. |
| 1209 | package is installed if it isn't already (@pxref{Installing | 1248 | |
| 1210 | packages}). | 1249 | First, add the following declaration to the beginning of your init |
| 1250 | file. The optional @w{@code{:ensure t}} makes sure the package is | ||
| 1251 | installed if it isn't already (@pxref{Installing packages}). | ||
| 1211 | 1252 | ||
| 1212 | @lisp | 1253 | @lisp |
| 1213 | (use-package diminish :ensure t) | 1254 | (use-package diminish :ensure t) |
| @@ -1231,7 +1272,9 @@ package name with @samp{-mode} appended at the end: | |||
| 1231 | 1272 | ||
| 1232 | @findex :delight | 1273 | @findex :delight |
| 1233 | When delight@footnote{The @samp{delight} package is installable from | 1274 | When delight@footnote{The @samp{delight} package is installable from |
| 1234 | GNU ELPA.} is installed, you can use the @code{:delight} keyword. | 1275 | GNU ELPA.} is installed, you can use the @code{:delight} keyword. If |
| 1276 | delight is not installed, the @code{:delight} keyword does nothing. | ||
| 1277 | |||
| 1235 | First, add the following declaration to the beginning of your init | 1278 | First, add the following declaration to the beginning of your init |
| 1236 | file. The optional @w{@code{:ensure t}} makes sure the package is | 1279 | file. The optional @w{@code{:ensure t}} makes sure the package is |
| 1237 | installed if it isn't already (@pxref{Installing packages}). | 1280 | installed if it isn't already (@pxref{Installing packages}). |
| @@ -1242,25 +1285,41 @@ installed if it isn't already (@pxref{Installing packages}). | |||
| 1242 | 1285 | ||
| 1243 | The @code{:delight} keyword takes a minor mode symbol, a replacement | 1286 | The @code{:delight} keyword takes a minor mode symbol, a replacement |
| 1244 | string, or quoted mode line data (in which case the minor mode symbol | 1287 | string, or quoted mode line data (in which case the minor mode symbol |
| 1245 | is guessed to be the package name with @samp{-mode} appended at the | 1288 | is assumed to be the package name with @samp{-mode} appended at the |
| 1246 | end), both of these, or several lists of both. @xref{Mode Line | 1289 | end), both of these, or several lists of both. @xref{Mode Line |
| 1247 | Data,,, elisp, GNU Emacs Lisp Reference Manual}. If no arguments are | 1290 | Data,,, elisp, GNU Emacs Lisp Reference Manual}. If no arguments are |
| 1248 | provided, the default mode name is hidden completely. | 1291 | provided, the default mode name is hidden completely. |
| 1249 | 1292 | ||
| 1293 | For example, the following hides everything for the @samp{foo-mode} | ||
| 1294 | minor mode in the @samp{foo} package: | ||
| 1295 | |||
| 1250 | @lisp | 1296 | @lisp |
| 1251 | ;; Don't show anything for rainbow-mode. | 1297 | (use-package foo |
| 1252 | (use-package rainbow-mode | ||
| 1253 | :delight) | 1298 | :delight) |
| 1299 | @end lisp | ||
| 1254 | 1300 | ||
| 1301 | If the mode name doesn't match the package name with @samp{-mode} | ||
| 1302 | appended, provide a symbol instead. For example, the following hides | ||
| 1303 | @code{auto-revert-mode} from the mode line: | ||
| 1304 | |||
| 1305 | @lisp | ||
| 1255 | ;; Don't show anything for auto-revert-mode, which doesn't match | 1306 | ;; Don't show anything for auto-revert-mode, which doesn't match |
| 1256 | ;; its package name. | 1307 | ;; its package name. |
| 1257 | (use-package autorevert | 1308 | (use-package autorevert |
| 1258 | :delight auto-revert-mode) | 1309 | :delight auto-revert-mode) |
| 1310 | @end lisp | ||
| 1259 | 1311 | ||
| 1260 | ;; Remove the mode name for projectile-mode, but show the project name. | 1312 | You can also run arbitrary Lisp code. For example, to replace |
| 1261 | (use-package projectile | 1313 | @samp{foo-mode} with the value of the current buffer: |
| 1262 | :delight '(:eval (concat " " (projectile-project-name)))) | ||
| 1263 | 1314 | ||
| 1315 | @lisp | ||
| 1316 | (use-package foo | ||
| 1317 | :delight '(:eval buffer-file-name)) | ||
| 1318 | @end lisp | ||
| 1319 | |||
| 1320 | Here is an example of hiding several built-in minor modes: | ||
| 1321 | |||
| 1322 | @lisp | ||
| 1264 | ;; Completely hide visual-line-mode and change auto-fill-mode to " AF". | 1323 | ;; Completely hide visual-line-mode and change auto-fill-mode to " AF". |
| 1265 | (use-package emacs | 1324 | (use-package emacs |
| 1266 | :delight | 1325 | :delight |
diff --git a/lisp/use-package/use-package-core.el b/lisp/use-package/use-package-core.el index 868a65803a4..ed6a65494fa 100644 --- a/lisp/use-package/use-package-core.el +++ b/lisp/use-package/use-package-core.el | |||
| @@ -1609,8 +1609,8 @@ no keyword implies `:all'." | |||
| 1609 | (defmacro use-package (name &rest args) | 1609 | (defmacro use-package (name &rest args) |
| 1610 | "Declare an Emacs package by specifying a group of configuration options. | 1610 | "Declare an Emacs package by specifying a group of configuration options. |
| 1611 | 1611 | ||
| 1612 | For full documentation, please see the README file that came with | 1612 | For the full documentation, see Info node `(use-package) top'. |
| 1613 | this file. Usage: | 1613 | Usage: |
| 1614 | 1614 | ||
| 1615 | (use-package package-name | 1615 | (use-package package-name |
| 1616 | [:keyword [option]]...) | 1616 | [:keyword [option]]...) |
| @@ -1647,12 +1647,15 @@ this file. Usage: | |||
| 1647 | `:magic-fallback', or `:interpreter'. This can be an integer, | 1647 | `:magic-fallback', or `:interpreter'. This can be an integer, |
| 1648 | to force loading after N seconds of idle time, if the package | 1648 | to force loading after N seconds of idle time, if the package |
| 1649 | has not already been loaded. | 1649 | has not already been loaded. |
| 1650 | :after Delay the use-package declaration until after the named modules | ||
| 1651 | have loaded. Once load, it will be as though the use-package | ||
| 1652 | declaration (without `:after') had been seen at that moment. | ||
| 1653 | :demand Prevent the automatic deferred loading introduced by constructs | 1650 | :demand Prevent the automatic deferred loading introduced by constructs |
| 1654 | such as `:bind' (see `:defer' for the complete list). | 1651 | such as `:bind' (see `:defer' for the complete list). |
| 1655 | 1652 | ||
| 1653 | :after Delay the effect of the use-package declaration | ||
| 1654 | until after the named libraries have loaded. | ||
| 1655 | Before they have been loaded, no other keyword | ||
| 1656 | has any effect at all, and once they have been | ||
| 1657 | loaded it is as if `:after' was not specified. | ||
| 1658 | |||
| 1656 | :if EXPR Initialize and load only if EXPR evaluates to a non-nil value. | 1659 | :if EXPR Initialize and load only if EXPR evaluates to a non-nil value. |
| 1657 | :disabled The package is ignored completely if this keyword is present. | 1660 | :disabled The package is ignored completely if this keyword is present. |
| 1658 | :defines Declare certain variables to silence the byte-compiler. | 1661 | :defines Declare certain variables to silence the byte-compiler. |