difference between (defalias 'A (symbol-function 'B)) and (defalias 'A 'B)

前端 未结 2 1751
面向向阳花
面向向阳花 2021-02-04 00:08

I was reading subr.el and saw this code:

(defalias \'backward-delete-char \'delete-backward-char)
(defalias \'search-forward-regexp (symbol-function \'re-search-         


        
2条回答
  •  一生所求
    2021-02-04 00:58

    The two defalias usages are slightly different. The first links the function cell for 'backward-delete-char to that of 'delete-backward-char. The second links the 'search-forward-regexp to the function that is currently called by 're-search-forward.

    The difference is that if you later change the definition of 'delete-backward-char, 'backward-delete-char will now have the new behavior. Whereas in the second case, changing the function for 're-search-forward has no effect on the behavior of 'search-forward-regexp.

    Perhaps some ascii art can help:

    +-------------------------+     +-----------------+
    |#| <-- |re-search-forward|
    +-------------------------+     +-----------------+
                            ^       +---------------------+
                            \------ |search-forward-regexp|
                                    +---------------------+
    
    +----------------------------+     +--------------------+     +--------------------+
    |#| <-- |delete-backward-char| <-- |backward-delete-char|
    +----------------------------+     +--------------------+     +--------------------+
    

    This documentation might help clear things up.

提交回复
热议问题