* doc/lispref/files.texi (Magic File Names): Add memory-info.
* doc/lispref/internals.texi (Garbage Collection): memory-info can
also retrieve values from remote systems.
* etc/NEWS: Document changes in memory-info. Fix typos.
* lisp/files.el (warn-maybe-out-of-memory): Ensure local memory info.
* lisp/net/tramp.el (tramp-handle-memory-info): New defun.
(tramp-file-name-for-operation)
* lisp/net/tramp-adb.el (tramp-adb-file-name-handler-alist):
* lisp/net/tramp-archive.el (tramp-archive-file-name-handler-alist):
* lisp/net/tramp-crypt.el (tramp-crypt-file-name-handler-alist):
* lisp/net/tramp-gvfs.el (tramp-gvfs-file-name-handler-alist):
* lisp/net/tramp-rclone.el (tramp-rclone-file-name-handler-alist):
* lisp/net/tramp-sh.el (tramp-sh-file-name-handler-alist):
* lisp/net/tramp-smb.el (tramp-smb-file-name-handler-alist):
* lisp/net/tramp-sshfs.el (tramp-sshfs-file-name-handler-alist)
* lisp/net/tramp-sudoedit.el (tramp-sudoedit-file-name-handler-alist):
Add 'memory-info'.
* lisp/net/tramp-sshfs.el (tramp-sshfs-handle-exec-path):
Let-bind `process-file-side-effects'.
* src/alloc.c (Fmemory_info): Support remote systems.
(Qmemory_info): Declare.
* test/lisp/net/tramp-tests.el (tramp-test31-memory-info): New test.
@code{make-nearby-temp-file},
@code{make-process},
@code{make-symbolic-link},@*
-@code{process-attributes}, @code{process-file},
+@code{memory-info}, @code{process-attributes}, @code{process-file},
@code{rename-file}, @code{set-file-acl}, @code{set-file-modes},
@code{set-file-selinux-context}, @code{set-file-times},
@code{set-visited-file-modtime}, @code{shell-command},
@code{make-nearby-temp-file},
@code{make-process},
@code{make-symbolic-link},
-@code{process-attributes}, @code{process-file},
+@code{memory-info}, @code{process-attributes}, @code{process-file},
@code{rename-file}, @code{set-file-acl}, @code{set-file-modes},
@code{set-file-selinux-context}, @code{set-file-times},
@code{set-visited-file-modtime}, @code{shell-command},
@defun memory-info
This functions returns an amount of total system memory and how much
of it is free. On an unsupported system, the value may be @code{nil}.
+
+If @code{default-directory} points to a remote host, memory
+information of that host is returned.
@end defun
@defvar gcs-done
are also obsolete.
---
-** The user function 'url-irc-function' now takes a 'scheme' argument.
+** The user function 'url-irc-function' now takes a SCHEME argument.
The user option 'url-irc-function' is now called with a sixth argument
corresponding to the scheme portion of the target URL. For example,
this would be "ircs" for a URL like "ircs://irc.libera.chat".
\f
* Changes in Specialized Modes and Packages in Emacs 29.1
-** ecomplete
+** Ecomplete
---
*** New commands 'ecomplete-edit' and 'ecomplete-remove'.
command is installed.
** CC Mode
+
---
*** C++ Mode now supports most of the new features in the C++20 standard.
it isn't already, and remove it if it is installed.
+++
-*** New command 'package-vc-install'
+*** New command 'package-vc-install'.
Packages can now be installed directly from source by cloning from a
repository.
+++
-*** New command 'package-vc-install-from-checkout'
+*** New command 'package-vc-install-from-checkout'.
An existing checkout can now be loaded via package.el, by creating a
symbolic link from the usual package directory to the checkout.
+++
-*** New command 'package-vc-checkout'
+*** New command 'package-vc-checkout'.
Used to fetch the source of a package by cloning a repository without
activating the package.
+++
-*** New command 'package-vc-prepare-patch'
+*** New command 'package-vc-prepare-patch'.
This command allows you to send patches to package maintainers, for
packages checked out using 'package-vc-install'.
+++
-*** New command 'package-report-bug'
+*** New command 'package-report-bug'.
This command helps you compose an email for sending bug reports to
package maintainers.
+++
-*** New user option 'package-vc-selected-packages'
+*** New user option 'package-vc-selected-packages'.
By customizing this user option you can specify specific packages to
install.
behaves after pressing a 'TAB' if completion is not unique. The value
'always' updates or shows the "*Completions*" buffer after any attempt
to complete. The value 'visual' is like 'always', but only updates
-the completions if they are already visible. The default value 't'
+the completions if they are already visible. The default value t
always hides the completion buffer after some completion is made.
*** New commands to complete the minibuffer history.
** EUDC
+++
-*** New user option 'eudc-ignore-options-file' that defaults to 'nil'
+*** New user option 'eudc-ignore-options-file' that defaults to nil.
The 'eudc-ignore-options-file' user option can be configured to ignore
the 'eudc-options-file' (typically "~/.emacs.d/eudc-options"). Most
-users should configure this to 't' and put EUDC configuration in the
-main Emacs initialization file (".emacs" or "~/.emacs.d/init.el").
+users should configure this to t and put EUDC configuration in the
+main Emacs initialization file ("~/.emacs" or "~/.emacs.d/init.el").
+++
*** 'eudc-expansion-overwrites-query' to 'eudc-expansion-save-query-as-kill'.
query results.
+++
-*** New back-end for ecomplete
+*** New back-end for ecomplete.
A new back-end for ecomplete allows information from that database to
be queried by EUDC, too. The attributes present in the EUDC query are
used to select the entry type in the ecomplete database.
+++
-*** New back-end for mailabbrev
+*** New back-end for mailabbrev.
A new back-end for mailabbrev allows information from that database to
-be queried by EUDC, too. The attributes email, name, and firstname
+be queried by EUDC, too. The attributes 'email', 'name', and 'firstname'
are supported only.
** EWW/SHR
---
*** New user option 'browse-url-irc-function'.
-This option specifies a function for opening irc:// links. It
+This option specifies a function for opening "irc://" links. It
defaults to the new function 'browse-url-irc'.
---
*** New function 'browse-url-irc'.
-This multipurpose autoloaded function can be used for opening irc://
-and ircs:// URLS by any caller that passes a URL string as an initial
+This multipurpose autoloaded function can be used for opening "irc://"
+and "ircs://" URLS by any caller that passes a URL string as an initial
arg.
---
symlinks in the latter case).
+++
-*** Lisp forms in Eshell now treat a 'nil' result as a failed exit status.
+*** Lisp forms in Eshell now treat a nil result as a failed exit status.
When executing a command that looks like '(lisp form)' and returns
-'nil', Eshell will set the exit status (available in the '$?'
+nil, Eshell will set the exit status (available in the '$?'
variable) to 2. This allows commands like that to be used in
conditionals. To change this behavior, customize the new
-'eshell-lisp-form-nil-is-failure' option.
+'eshell-lisp-form-nil-is-failure' user option.
** Shell
The old name is still available as an obsolete function alias.
---
-*** The url-irc library now understands ircs:// links.
+*** The url-irc library now understands "ircs://" links.
---
*** New command 'world-clock-copy-time-as-kill' for 'M-x world-clock'.
name.
---
-*** New key binding "O" in `M-x list-buffer'.
+*** New key binding 'O' in 'M-x list-buffer'.
This key is now bound to 'Buffer-menu-view-other-window', which will
view this line's buffer in View mode in another window.
This is a lightweight variant of 'js-mode' that is used by default
when visiting JSON files.
-\f
** New mode 'typescript-ts-mode'.
A major mode based on the tree-sitter library for editing programs
in the TypeScript language. It includes support for font-locking,
moved to 'internal-default-signal-process'.
+++
-** 'list-system-processes' now returns remote process IDs.
+** Some system information functions honor remote systems now.
+'list-system-processes' returns remote process IDs.
+'memory-info' returns memory information of remote systems.
+'process-attributes' expects a remote process ID.
This happens only when the current buffer's 'default-directory' is
-remote. In order to preserve the old behavior, apply
+remote. In order to preserve the old behavior, bind
+'default-directory' to a local directory, like
(let ((default-directory temporary-file-directory))
(list-system-processes))
-+++
-** 'process-attributes' expects a remote process ID now.
-When current buffer's 'default-directory' is remote, the PID argument
-of 'process-attributes' is regarded as a remote process ID. In order
-to preserve the old behavior, apply
-
- (let ((default-directory temporary-file-directory))
- (process-attributes pid))
-
+++
** New functions 'take' and 'ntake'.
'(take N LIST)' returns the first N elements of LIST; 'ntake' does
You should have received a copy of the GNU General Public License
along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
-
-\f
-Local variables:
-coding: utf-8
-mode: outline
-mode: emacs-news
-paragraph-separate: "[ \f]"
-end:
"Warn if an attempt to open file of SIZE bytes may run out of memory."
(when (and (numberp size) (not (zerop size))
(integerp out-of-memory-warning-percentage))
- (let ((meminfo (memory-info)))
+ (let* ((default-directory temporary-file-directory)
+ (meminfo (memory-info)))
(when (consp meminfo)
(let ((total-free-memory (float (+ (nth 1 meminfo) (nth 3 meminfo)))))
(when (> (/ size 1024)
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . tramp-adb-handle-make-process)
(make-symbolic-link . tramp-handle-make-symbolic-link)
+ (memory-info . tramp-handle-memory-info)
(process-attributes . tramp-handle-process-attributes)
(process-file . tramp-adb-handle-process-file)
(rename-file . tramp-adb-handle-rename-file)
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . ignore)
(make-symbolic-link . tramp-archive-handle-not-implemented)
+ ;; `memory-info' performed by default handler.
(process-attributes . ignore)
(process-file . ignore)
(rename-file . tramp-archive-handle-not-implemented)
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . ignore)
(make-symbolic-link . tramp-handle-make-symbolic-link)
+ (memory-info . ignore)
(process-attributes . ignore)
(process-file . ignore)
(rename-file . tramp-crypt-handle-rename-file)
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . ignore)
(make-symbolic-link . tramp-handle-make-symbolic-link)
+ (memory-info . ignore)
(process-attributes . ignore)
(process-file . ignore)
(rename-file . tramp-gvfs-handle-rename-file)
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . ignore)
(make-symbolic-link . tramp-handle-make-symbolic-link)
+ (memory-info . ignore)
(process-attributes . ignore)
(process-file . ignore)
(rename-file . tramp-rclone-handle-rename-file)
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . tramp-sh-handle-make-process)
(make-symbolic-link . tramp-sh-handle-make-symbolic-link)
+ (memory-info . tramp-handle-memory-info)
(process-attributes . tramp-handle-process-attributes)
(process-file . tramp-sh-handle-process-file)
(rename-file . tramp-sh-handle-rename-file)
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . ignore)
(make-symbolic-link . tramp-smb-handle-make-symbolic-link)
+ (memory-info . ignore)
(process-attributes . ignore)
(process-file . tramp-smb-handle-process-file)
(rename-file . tramp-smb-handle-rename-file)
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . tramp-handle-make-process)
(make-symbolic-link . tramp-handle-make-symbolic-link)
+ (memory-info . tramp-handle-memory-info)
(process-attributes . tramp-handle-process-attributes)
(process-file . tramp-sshfs-handle-process-file)
(rename-file . tramp-sshfs-handle-rename-file)
(with-parsed-tramp-file-name default-directory nil
(with-tramp-connection-property (tramp-get-process v) "remote-path"
(with-temp-buffer
- (process-file "getconf" nil t nil "PATH")
+ (let (process-file-side-effects)
+ (process-file "getconf" nil t nil "PATH"))
(split-string
(progn
;; Read the expression.
(make-nearby-temp-file . tramp-handle-make-nearby-temp-file)
(make-process . ignore)
(make-symbolic-link . tramp-sudoedit-handle-make-symbolic-link)
+ (memory-info . ignore)
(process-attributes . ignore)
(process-file . ignore)
(rename-file . tramp-sudoedit-handle-rename-file)
;; Emacs 27+ only.
exec-path make-process
;; Emacs 29+ only.
- list-system-processes process-attributes))
+ list-system-processes memory-info process-attributes))
default-directory)
;; PROC.
((member operation '(file-notify-rm-watch file-notify-valid-p))
(tramp-dissect-file-name (expand-file-name linkname)) 'file-error
"make-symbolic-link not supported"))
+(defun tramp-handle-memory-info ()
+ "Like `memory-info' for Tramp files."
+ (let ((result '(0 0 0 0))
+ process-file-side-effects)
+ (with-temp-buffer
+ (cond
+ ;; GNU/Linux.
+ ((zerop (process-file "cat" nil '(t) nil "/proc/meminfo"))
+ (goto-char (point-min))
+ (when
+ (re-search-forward
+ (rx bol "MemTotal:" (* space) (group (+ digit)) (* space) "kB" eol)
+ nil 'noerror)
+ (setcar (nthcdr 0 result) (string-to-number (match-string 1))))
+ (goto-char (point-min))
+ (when
+ (re-search-forward
+ (rx bol "MemFree:" (* space) (group (+ digit)) (* space) "kB" eol)
+ nil 'noerror)
+ (setcar (nthcdr 1 result) (string-to-number (match-string 1))))
+ (goto-char (point-min))
+ (when
+ (re-search-forward
+ (rx bol "SwapTotal:" (* space) (group (+ digit)) (* space) "kB" eol)
+ nil 'noerror)
+ (setcar (nthcdr 2 result) (string-to-number (match-string 1))))
+ (goto-char (point-min))
+ (when
+ (re-search-forward
+ (rx bol "SwapFree:" (* space) (group (+ digit)) (* space) "kB" eol)
+ nil 'noerror)
+ (setcar (nthcdr 3 result) (string-to-number (match-string 1)))))
+
+ ;; BSD.
+ ;; https://raw.githubusercontent.com/ocochard/myscripts/master/FreeBSD/freebsd-memory.sh
+ ((zerop (process-file "sysctl" nil '(t) nil "-a"))
+ (goto-char (point-min))
+ (when
+ (re-search-forward
+ (rx bol "hw.pagesize:" (* space) (group (+ digit)) eol)
+ nil 'noerror)
+ (let ((pagesize (string-to-number (match-string 1))))
+ (goto-char (point-min))
+ (when
+ (re-search-forward
+ (rx bol "vm.stats.vm.v_page_count:" (* space)
+ (group (+ digit)) eol)
+ nil 'noerror)
+ (setcar
+ (nthcdr 0 result)
+ (/ (* (string-to-number (match-string 1)) pagesize) 1024)))
+ (goto-char (point-min))
+ (when
+ (re-search-forward
+ (rx bol "vm.stats.vm.v_free_count:" (* space)
+ (group (+ digit)) eol)
+ nil 'noerror)
+ (setcar
+ (nthcdr 1 result)
+ (/ (* (string-to-number (match-string 1)) pagesize) 1024)))))
+ (erase-buffer)
+ (when (zerop (process-file "swapctl" nil '(t) nil "-sk"))
+ (goto-char (point-min))
+ (when
+ (re-search-forward
+ (rx bol "Total:" (* space)
+ (group (+ digit)) (* space) (group (+ digit)) eol)
+ nil 'noerror)
+ (setcar (nthcdr 2 result) (string-to-number (match-string 1)))
+ (setcar
+ (nthcdr 3 result)
+ (- (string-to-number (match-string 1))
+ (string-to-number (match-string 2)))))))))
+
+ ;; Return result.
+ (unless (equal result '(0 0 0 0))
+ result)))
+
(defun tramp-handle-process-attributes (pid)
"Like `process-attributes' for Tramp files."
(catch 'result
doc: /* Return a list of (TOTAL-RAM FREE-RAM TOTAL-SWAP FREE-SWAP).
All values are in Kbytes. If there is no swap space,
last two values are zero. If the system is not supported
-or memory information can't be obtained, return nil. */)
+or memory information can't be obtained, return nil.
+If `default-directory’ is remote, return memory information of the
+respective remote host. */)
(void)
{
+ Lisp_Object handler
+ = Ffind_file_name_handler (BVAR (current_buffer, directory),
+ Qmemory_info);
+ if (!NILP (handler))
+ return call1 (handler, Qmemory_info);
+
#if defined HAVE_LINUX_SYSINFO
struct sysinfo si;
uintmax_t units;
doc: /* Non-nil means Emacs cannot get much more Lisp memory. */);
Vmemory_full = Qnil;
+ DEFSYM (Qmemory_info, "memory-info");
+
DEFSYM (Qconses, "conses");
DEFSYM (Qsymbols, "symbols");
DEFSYM (Qstrings, "strings");
;; Cleanup.
(ignore-errors (delete-process proc)))))
+(ert-deftest tramp-test31-memory-info ()
+ "Check `memory-info'."
+ :tags '(:expensive-test)
+ (skip-unless (tramp--test-enabled))
+ (skip-unless (tramp--test-supports-processes-p))
+ ;; `memory-info' is supported since Emacs 29.1.
+ (skip-unless (tramp--test-emacs29-p))
+
+ (when-let ((default-directory ert-remote-temporary-file-directory)
+ (mi (memory-info)))
+ (should (consp mi))
+ (should (= (length mi) 4))
+ (dotimes (i (length mi))
+ (should (natnump (nth i mi))))))
+
(defun tramp--test-async-shell-command
(command output-buffer &optional error-buffer input)
"Like `async-shell-command', reading the output.