]> git.eshelyaron.com Git - emacs.git/commitdiff
New commands 'apropos-local-variable', 'apropos-local-value'
authorDrew Adams <drew.adams@oracle.com>
Fri, 28 Jul 2017 07:47:20 +0000 (10:47 +0300)
committerEli Zaretskii <eliz@gnu.org>
Fri, 28 Jul 2017 07:47:20 +0000 (10:47 +0300)
* lisp/apropos.el (apropos-local-variable, apropos-local-value):
New functions.  (Bug#27424)

* doc/emacs/help.texi (Apropos): Document 'apropos-local-variable'
and 'apropos-local-value'.
* etc/NEWS: Mention the new commands.

doc/emacs/help.texi
etc/NEWS
lisp/apropos.el

index fd6df1c7e53f6dbd944af0846b2ace4ef29bad4b..460ced0d21c55183e9f5c74ea45c17a738524dfb 100644 (file)
@@ -320,12 +320,21 @@ search for non-customizable variables too.
 Search for variables.  With a prefix argument, search for
 customizable variables only.
 
+@item M-x apropos-local-variable
+@findex apropos-local-variable
+Search for buffer-local variables.
+
 @item M-x apropos-value
 @findex apropos-value
 Search for variables whose values match the specified pattern.  With a
 prefix argument, search also for functions with definitions matching
 the pattern, and Lisp symbols with properties matching the pattern.
 
+@item M-x apropos-local-value
+@findex apropos-local-value
+Search for buffer-local variables whose values match the specified
+pattern.
+
 @item C-h d
 @kindex C-h d
 @findex apropos-documentation
index f43491b63060beae3a0530716f2f67423141a2fe..a7800feed1f14a5afdea570eef4775825df2d34b 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -589,6 +589,12 @@ current buffer with the contents of the accessible portion of a
 different buffer while keeping point, mark, markers, and text
 properties as intact as possible.
 
++++
+** New commands 'apropos-local-variable' and 'apropos-local-value.
+These are buffer-local versions of 'apropos-variable' and
+'apropos-value', respectively.  They show buffer-local variables whose
+names and values, respectively, match a given pattern.
+
 +++
 ** More user control of reordering bidirectional text for display.
 The two new variables, 'bidi-paragraph-start-re' and
index cbd9c71d3e356c70188c215e6f06ed2da2f40df8..86d9b51429027dc374844e537be6d328866aab1a 100644 (file)
@@ -514,6 +514,19 @@ options only, i.e. behave like `apropos-user-option'."
   (let ((apropos-do-all (if do-not-all nil t)))
     (apropos-user-option pattern)))
 
+;;;###autoload
+(defun apropos-local-variable (pattern &optional buffer)
+  "Show buffer-local variables that match PATTERN.
+Optional arg BUFFER (default: current buffer) is the buffer to check.
+
+The output includes variables that are not yet set in BUFFER, but that
+will be buffer-local when set."
+  (interactive (list (apropos-read-pattern "buffer-local variable")))
+  (unless buffer (setq buffer  (current-buffer)))
+  (apropos-command pattern nil (lambda (symbol)
+                                 (and (local-variable-if-set-p symbol)
+                                      (get symbol 'variable-documentation)))))
+
 ;; For auld lang syne:
 ;;;###autoload
 (defalias 'command-apropos 'apropos-command)
@@ -795,6 +808,35 @@ Returns list of symbols and values found."
    (let ((apropos-multi-type do-all))
      (apropos-print nil "\n----------------\n")))
 
+;;;###autoload
+(defun apropos-local-value (pattern &optional buffer)
+  "Show buffer-local variables whose values match PATTERN.
+This is like `apropos-value', but only for buffer-local variables.
+Optional arg BUFFER (default: current buffer) is the buffer to check."
+  (interactive (list (apropos-read-pattern "value of buffer-local variable")))
+  (unless buffer (setq buffer  (current-buffer)))
+  (apropos-parse-pattern pattern)
+  (setq apropos-accumulator  ())
+  (let ((var             nil))
+    (mapatoms
+     (lambda (symb)
+       (unless (memq symb '(apropos-regexp apropos-pattern apropos-all-words-regexp
+                            apropos-words apropos-all-words apropos-accumulator symb var))
+         (setq var  (apropos-value-internal 'local-variable-if-set-p symb 'symbol-value)))
+       (when (and (fboundp 'apropos-false-hit-str)  (apropos-false-hit-str var))
+         (setq var nil))
+       (when var
+         (setq apropos-accumulator (cons (list symb (apropos-score-str var) nil var)
+                                         apropos-accumulator))))))
+  (let ((apropos-multi-type  nil))
+    (if (> emacs-major-version 20)
+        (apropos-print
+         nil "\n----------------\n"
+         (format "Buffer `%s' has the following local variables\nmatching %s`%s':"
+                 (buffer-name buffer)
+                 (if (consp pattern) "keywords " "")
+                 pattern))
+      (apropos-print nil "\n----------------\n"))))
 
 ;;;###autoload
 (defun apropos-documentation (pattern &optional do-all)