emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r111134: * lisp/ses.el: Use advice-ad


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r111134: * lisp/ses.el: Use advice-add/remove.
Date: Thu, 06 Dec 2012 15:16:38 -0500
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111134
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Thu 2012-12-06 15:16:38 -0500
message:
  * lisp/ses.el: Use advice-add/remove.
  (ses--advice-copy-region-as-kill, ses--advice-yank): New functions.
  (copy-region-as-kill, yank): Use advice-add.
  (ses-unload-function): Use advice-remove.
modified:
  lisp/ChangeLog
  lisp/ses.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-12-06 20:10:36 +0000
+++ b/lisp/ChangeLog    2012-12-06 20:16:38 +0000
@@ -1,3 +1,10 @@
+2012-12-06  Stefan Monnier  <address@hidden>
+
+       * ses.el: Use advice-add/remove.
+       (ses--advice-copy-region-as-kill, ses--advice-yank): New functions.
+       (copy-region-as-kill, yank): Use advice-add.
+       (ses-unload-function): Use advice-remove.
+
 2012-12-06  Jonas Bernoulli  <address@hidden>
 
        * button.el: Make them work in header-lines (bug#12817).

=== modified file 'lisp/ses.el'
--- a/lisp/ses.el       2012-11-24 17:44:29 +0000
+++ b/lisp/ses.el       2012-12-06 20:16:38 +0000
@@ -2718,8 +2718,9 @@
 ;; Cut and paste, import and export
 ;;----------------------------------------------------------------------------
 
-(defadvice copy-region-as-kill (around ses-copy-region-as-kill
-                               activate preactivate)
+(defun ses--advice-copy-region-as-kill (crak-fun beg end &rest args)
+  ;; FIXME: Why doesn't it make sense to copy read-only or
+  ;; intangible attributes?  They're removed upon yank!
   "It doesn't make sense to copy read-only or intangible attributes into the
 kill ring.  It probably doesn't make sense to copy keymap properties.
 We'll assume copying front-sticky properties doesn't make sense, either.
@@ -2730,14 +2731,15 @@
     (let ((temp beg))
       (setq beg end
            end temp)))
-  (if (not (and (eq major-mode 'ses-mode)
+  (if (not (and (derived-mode-p 'ses-mode)
                (eq (get-text-property beg 'read-only) 'ses)
                (eq (get-text-property (1- end) 'read-only) 'ses)))
-      ad-do-it ; Normal copy-region-as-kill.
+      (apply crak-fun beg end args) ; Normal copy-region-as-kill.
     (kill-new (ses-copy-region beg end))
     (if transient-mark-mode
        (setq deactivate-mark t))
     nil))
+(advice-add 'copy-region-as-kill :around #'ses--advice-copy-region-as-kill)
 
 (defun ses-copy-region (beg end)
   "Treat the region as rectangular.  Convert the intangible attributes to
@@ -2801,7 +2803,7 @@
     (ses-clear-cell row col))
   (ses-jump (car ses--curcell)))
 
-(defadvice yank (around ses-yank activate preactivate)
+(defun ses--advice-yank (yank-fun &optional arg &rest args)
   "In SES mode, the yanked text is inserted as cells.
 
 If the text contains 'ses attributes (meaning it went to the kill-ring from a
@@ -2819,9 +2821,9 @@
 make sense as a sexp or would otherwise be considered a symbol.  Use 'sym to
 explicitly insert a symbol, or use the C-u prefix to treat all unmarked words
 as symbols."
-  (if (not (and (eq major-mode 'ses-mode)
+  (if (not (and (derived-mode-p 'ses-mode)
                (eq (get-text-property (point) 'keymap) 'ses-mode-print-map)))
-      ad-do-it ; Normal non-SES yank.
+      (apply yank-fun arg args) ; Normal non-SES yank.
     (ses-check-curcell 'end)
     (push-mark (point))
     (let ((text (current-kill (cond
@@ -2839,6 +2841,7 @@
                        arg)))
     (if (consp arg)
        (exchange-point-and-mark))))
+(advice-add 'yank :around #'ses--advice-yank)
 
 (defun ses-yank-pop (arg)
   "Replace just-yanked stretch of killed text with a different stretch.
@@ -3586,10 +3589,9 @@
 
 (defun ses-unload-function ()
   "Unload the Simple Emacs Spreadsheet."
-  (dolist (fun '(copy-region-as-kill yank))
-    (ad-remove-advice fun 'around (intern (concat "ses-" (symbol-name fun))))
-    (ad-update fun))
-  ;; continue standard unloading
+  (advice-remove 'yank #'ses--advice-yank)
+  (advice-remove 'copy-region-as-kill #'ses--advice-copy-region-as-kill)
+  ;; Continue standard unloading.
   nil)
 
 (provide 'ses)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]