diff options
| -rw-r--r-- | doc/lispref/modes.texi | 10 | ||||
| -rw-r--r-- | etc/NEWS | 6 | ||||
| -rw-r--r-- | lisp/bindings.el | 64 |
3 files changed, 80 insertions, 0 deletions
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi index 8ca0afe1bca..b4f69e79155 100644 --- a/doc/lispref/modes.texi +++ b/doc/lispref/modes.texi | |||
| @@ -2277,6 +2277,16 @@ current buffer is remote. | |||
| 2277 | This variable is used to identify @code{emacsclient} frames. | 2277 | This variable is used to identify @code{emacsclient} frames. |
| 2278 | @end defvar | 2278 | @end defvar |
| 2279 | 2279 | ||
| 2280 | @defvar mode-line-format-right-align | ||
| 2281 | Anything following this symbol in @code{mode-line-format} will be | ||
| 2282 | right-aligned. | ||
| 2283 | @end defvar | ||
| 2284 | |||
| 2285 | @defvar mode-line-right-align-edge | ||
| 2286 | This variable controls exactly @code{mode-line-format-right-align} | ||
| 2287 | aligns content to. | ||
| 2288 | @end defvar | ||
| 2289 | |||
| 2280 | The following three variables are used in @code{mode-line-modes}: | 2290 | The following three variables are used in @code{mode-line-modes}: |
| 2281 | 2291 | ||
| 2282 | @defvar mode-name | 2292 | @defvar mode-name |
| @@ -92,6 +92,12 @@ plus, minus, check-mark, start, etc. | |||
| 92 | The 'tool-bar-position' frame parameter can be set to 'bottom' on all | 92 | The 'tool-bar-position' frame parameter can be set to 'bottom' on all |
| 93 | window systems other than Nextstep. | 93 | window systems other than Nextstep. |
| 94 | 94 | ||
| 95 | ** Modeline elements can now be right-aligned | ||
| 96 | Anything following the symbol 'mode-line-format-right-align' in | ||
| 97 | 'mode-line-format' will be right-aligned. Exactly where it is | ||
| 98 | right-aligned to is controlled by the new user option | ||
| 99 | 'mode-line-right-align-edge'. | ||
| 100 | |||
| 95 | 101 | ||
| 96 | * Editing Changes in Emacs 30.1 | 102 | * Editing Changes in Emacs 30.1 |
| 97 | 103 | ||
diff --git a/lisp/bindings.el b/lisp/bindings.el index c77b64c05da..f1a75b080be 100644 --- a/lisp/bindings.el +++ b/lisp/bindings.el | |||
| @@ -304,6 +304,70 @@ Normally nil in most modes, since there is no process to display.") | |||
| 304 | ;;;###autoload | 304 | ;;;###autoload |
| 305 | (put 'mode-line-process 'risky-local-variable t) | 305 | (put 'mode-line-process 'risky-local-variable t) |
| 306 | 306 | ||
| 307 | (defcustom mode-line-right-align-edge 'window | ||
| 308 | "Where function `mode-line-format-right-align' should align to. | ||
| 309 | Internally, that function uses `:align-to' in a display property, | ||
| 310 | so aligns to the left edge of the given area. See info node | ||
| 311 | `(elisp)Pixel Specification'. | ||
| 312 | |||
| 313 | Must be set to a symbol. Acceptable values are: | ||
| 314 | - `window': align to extreme right of window, regardless of margins | ||
| 315 | or fringes | ||
| 316 | - `right-fringe': align to right-fringe | ||
| 317 | - `right-margin': align to right-margin" | ||
| 318 | :type '(choice (const right-margin) | ||
| 319 | (const right-fringe) | ||
| 320 | (const window)) | ||
| 321 | :group 'mode-line | ||
| 322 | :version "30.1") | ||
| 323 | |||
| 324 | (defun mode--line-format-right-align () | ||
| 325 | "Right-align all following mode-line constructs. | ||
| 326 | |||
| 327 | When the symbol `mode-line-format-right-align' appears in | ||
| 328 | `mode-line-format', return a string of one space, with a display | ||
| 329 | property to make it appear long enough to align anything after | ||
| 330 | that symbol to the right of the rendered mode line. Exactly how | ||
| 331 | far to the right is controlled by `mode-line-right-align-edge'. | ||
| 332 | |||
| 333 | It is important that the symbol `mode-line-format-right-align' be | ||
| 334 | included in `mode-line-format' (and not another similar construct | ||
| 335 | such as `(:eval (mode-line-format-right-align)'). This is because | ||
| 336 | the symbol `mode-line-format-right-align' is processed by | ||
| 337 | `format-mode-line' as a variable." | ||
| 338 | (let* ((rest (cdr (memq 'mode-line-format-right-align | ||
| 339 | mode-line-format))) | ||
| 340 | (rest-str (format-mode-line `("" ,@rest))) | ||
| 341 | (rest-width (string-pixel-width rest-str))) | ||
| 342 | (propertize " " 'display | ||
| 343 | ;; The `right' spec doesn't work on TTY frames | ||
| 344 | ;; when windows are split horizontally (bug#59620) | ||
| 345 | (if (and (display-graphic-p) | ||
| 346 | (not (eq mode-line-right-align-edge 'window))) | ||
| 347 | `(space :align-to (- ,mode-line-right-align-edge | ||
| 348 | (,rest-width))) | ||
| 349 | `(space :align-to (,(- (window-pixel-width) | ||
| 350 | (window-scroll-bar-width) | ||
| 351 | (window-right-divider-width) | ||
| 352 | (* (or (cdr (window-margins)) 1) | ||
| 353 | (frame-char-width)) | ||
| 354 | ;; Manually account for value of | ||
| 355 | ;; `mode-line-right-align-edge' even | ||
| 356 | ;; when display is non-graphical | ||
| 357 | (pcase mode-line-right-align-edge | ||
| 358 | ('right-margin | ||
| 359 | (or (cdr (window-margins)) 0)) | ||
| 360 | ('right-fringe | ||
| 361 | ;; what here? | ||
| 362 | (or (cadr (window-fringes)) 0)) | ||
| 363 | (_ 0)) | ||
| 364 | rest-width))))))) | ||
| 365 | |||
| 366 | (defvar mode-line-format-right-align '(:eval (mode--line-format-right-align)) | ||
| 367 | "Mode line construct to right align all following constructs.") | ||
| 368 | ;;;###autoload | ||
| 369 | (put 'mode-line-format-right-align 'risky-local-variable t) | ||
| 370 | |||
| 307 | (defun bindings--define-key (map key item) | 371 | (defun bindings--define-key (map key item) |
| 308 | "Define KEY in keymap MAP according to ITEM from a menu. | 372 | "Define KEY in keymap MAP according to ITEM from a menu. |
| 309 | This is like `define-key', but it takes the definition from the | 373 | This is like `define-key', but it takes the definition from the |