How to find aliases in emacs

I want to check if there is a default \ existing aliasing for the function (in this case:, x-clipboard-yankbut the question is general).
Is there an emacs function that displays active aliases that I can use to figure this out?
The expected behavior is similar to a shell command alias.

+4
source share
2 answers

You can check the value (symbol-function 'THE-FUNCTION). If the value is a symbol, then it THE-FUNCTIONis an alias.

, THE-FUNCTION, defalias ( fset). THE-FUNCTION , (, - ) (, ).

, , - , , . , symbol-function nil, , . ( nil , , - .)

, :

(defun aliased-p (fn)
  "Return non-nil if function FN is aliased to a function symbol."
  (let ((val  (symbol-function fn)))
    (and val                            ; `nil' means not aliased
         (symbolp val))))

: :

(defun aliased-p (fn &optional msgp)
  "Prompt for a function name and say whether it is an alias.
Return non-nil if the function is aliased."
  (interactive "aFunction: \np")
  (let* ((val  (symbol-function fn))
         (ret  (and val  (symbolp val))))
    (when msgp (message "`%s' %s an alias" fn (if ret "IS" "is NOT")))
    ret))

- :

(defalias 'foo (symbol-function 'bar))

foo bar. bar, foo. foo - bar defalias ing.

:

(defalias 'foo 'bar)

foo bar. foo - bar: (symbol-function 'foo)= bar. , bar , foo.

+4

, , , , - " ", .

, , , mapatoms :

(defun get-aliases (fn-symbol)
  "Return a list of aliases for the given function."
  (let ((aliases nil))
    (mapatoms (lambda (sym)
                (if (eq fn-symbol (symbol-function sym))
                    (setq aliases (cons sym aliases)))))
    (nreverse aliases)))

.

(get-aliases 'cl-caddr) => (caddr cl-third)

caddr cl-third ' ' cl-caddr.

0

All Articles