bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#10760: 24.0.93; [patch] Convert artist-mode to use define-minor-mode


From: William Stevenson
Subject: bug#10760: 24.0.93; [patch] Convert artist-mode to use define-minor-mode
Date: Wed, 08 Feb 2012 07:12:38 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.93 (gnu/linux)

This is my first patch concerning the item in etc/TODO:
** Check what minor modes don't use define-minor-mode and convert them
to use it.

Please look carefully at the change I made to the last item in the
mode-map. The original code was:
(define-key map [menu-bar artist] (cons "Artist" artist-menu-map))
I found I needed to change this to:
([menu-bar artist]      .       artist-menu-map))
This works the same, but I'm unsure as to any wider effects it may have.

Also consider removing as redundant the function artist-mode-off, the
keymap for this and the mention in the documentation.

After the changes artist-mode-name was only referred to in
artist-mode-line-show-curr-operation, and it seemed sensible to replace
it with the string, as in this case it is just concat'ed to "/".

I have cc'ed the maintainer Tomas Abrahamsson this message.

=== modified file 'lisp/textmodes/artist.el'
*** lisp/textmodes/artist.el    2012-01-19 07:21:25 +0000
--- lisp/textmodes/artist.el    2012-02-08 07:09:41 +0000
***************
*** 415,427 ****
  
  ;; Internal variables
  ;;
- (defvar artist-mode nil
-   "Non-nil to enable `artist-mode' and nil to disable.")
- (make-variable-buffer-local 'artist-mode)
- 
- (defvar artist-mode-name " Artist"
-   "Name of Artist mode beginning with a space (appears in the mode-line).")
- 
  (defvar artist-curr-go 'pen-line
    "Current selected graphics operation.")
  (make-variable-buffer-local 'artist-curr-go)
--- 415,420 ----
***************
*** 545,606 ****
                    :button (:radio . (eq artist-curr-go ',(nth 2 op))))))
      map))
  
- (defvar artist-mode-map
-   (let ((map (make-sparse-keymap)))
-     (setq artist-mode-map (make-sparse-keymap))
-     (define-key map [down-mouse-1] 'artist-down-mouse-1)
-     (define-key map [S-down-mouse-1] 'artist-down-mouse-1)
-     (define-key map [down-mouse-2] 'artist-mouse-choose-operation)
-     (define-key map [S-down-mouse-2] 'artist-mouse-choose-operation)
-     (define-key map [down-mouse-3] 'artist-down-mouse-3)
-     (define-key map [S-down-mouse-3] 'artist-down-mouse-3)
-     (define-key map [C-mouse-4] 'artist-select-prev-op-in-list)
-     (define-key map [C-mouse-5] 'artist-select-next-op-in-list)
-     (define-key map "\r" 'artist-key-set-point) ; return
-     (define-key map [up] 'artist-previous-line)
-     (define-key map "\C-p" 'artist-previous-line)
-     (define-key map [down] 'artist-next-line)
-     (define-key map "\C-n" 'artist-next-line)
-     (define-key map [left] 'artist-backward-char)
-     (define-key map "\C-b" 'artist-backward-char)
-     (define-key map [right] 'artist-forward-char)
-     (define-key map "\C-f" 'artist-forward-char)
-     (define-key map "<" 'artist-toggle-first-arrow)
-     (define-key map ">" 'artist-toggle-second-arrow)
-     (define-key map "\C-c\C-a\C-e" 'artist-select-erase-char)
-     (define-key map "\C-c\C-a\C-f" 'artist-select-fill-char)
-     (define-key map "\C-c\C-a\C-l" 'artist-select-line-char)
-     (define-key map "\C-c\C-a\C-o" 'artist-select-operation)
-     (define-key map "\C-c\C-a\C-r" 'artist-toggle-rubber-banding)
-     (define-key map "\C-c\C-a\C-t" 'artist-toggle-trim-line-endings)
-     (define-key map "\C-c\C-a\C-s" 'artist-toggle-borderless-shapes)
-     (define-key map "\C-c\C-c"     'artist-mode-off)
-     (define-key map "\C-c\C-al"    'artist-select-op-line)
-     (define-key map "\C-c\C-aL"    'artist-select-op-straight-line)
-     (define-key map "\C-c\C-ar"    'artist-select-op-rectangle)
-     (define-key map "\C-c\C-aR"    'artist-select-op-square)
-     (define-key map "\C-c\C-as"    'artist-select-op-square)
-     (define-key map "\C-c\C-ap"    'artist-select-op-poly-line)
-     (define-key map "\C-c\C-aP"    'artist-select-op-straight-poly-line)
-     (define-key map "\C-c\C-ae"    'artist-select-op-ellipse)
-     (define-key map "\C-c\C-ac"    'artist-select-op-circle)
-     (define-key map "\C-c\C-at"    'artist-select-op-text-see-thru)
-     (define-key map "\C-c\C-aT"    'artist-select-op-text-overwrite)
-     (define-key map "\C-c\C-aS"    'artist-select-op-spray-can)
-     (define-key map "\C-c\C-az"    'artist-select-op-spray-set-size)
-     (define-key map "\C-c\C-a\C-d" 'artist-select-op-erase-char)
-     (define-key map "\C-c\C-aE"    'artist-select-op-erase-rectangle)
-     (define-key map "\C-c\C-av"    'artist-select-op-vaporize-line)
-     (define-key map "\C-c\C-aV"    'artist-select-op-vaporize-lines)
-     (define-key map "\C-c\C-a\C-k" 'artist-select-op-cut-rectangle)
-     (define-key map "\C-c\C-a\M-w" 'artist-select-op-copy-rectangle)
-     (define-key map "\C-c\C-a\C-y" 'artist-select-op-paste)
-     (define-key map "\C-c\C-af"    'artist-select-op-flood-fill)
-     (define-key map "\C-c\C-a\C-b" 'artist-submit-bug-report)
-     (define-key map [menu-bar artist] (cons "Artist" artist-menu-map))
-     map)
-   "Keymap for `artist-minor-mode'.")
- 
  (defvar artist-replacement-table (make-vector 256 0)
    "Replacement table for `artist-replace-char'.")
  
--- 538,543 ----
***************
*** 1196,1204 ****
  ;;; ---------------------------------
  
  ;;;###autoload
! (defun artist-mode (&optional state)
    "Toggle Artist mode.
! With argument STATE, turn Artist mode on if STATE is positive.
  Artist lets you draw lines, squares, rectangles and poly-lines,
  ellipses and circles with your mouse and/or keyboard.
  
--- 1133,1141 ----
  ;;; ---------------------------------
  
  ;;;###autoload
! (define-minor-mode artist-mode
    "Toggle Artist mode.
! With argument ARG, turn Artist mode on if ARG is positive.
  Artist lets you draw lines, squares, rectangles and poly-lines,
  ellipses and circles with your mouse and/or keyboard.
  
***************
*** 1227,1233 ****
                --------------------------------------------------------------
                  Pen             fill-char at point        line from last point
                                                            to new point
!               --------------------------------------------------------------
                Line            Line in any direction     Straight line
                --------------------------------------------------------------
                Rectangle       Rectangle                 Square
--- 1164,1170 ----
                --------------------------------------------------------------
                  Pen             fill-char at point        line from last point
                                                            to new point
!  --------------------------------------------------------------
                Line            Line in any direction     Straight line
                --------------------------------------------------------------
                Rectangle       Rectangle                 Square
***************
*** 1387,1472 ****
  
  Hooks
  
!  When entering artist-mode, the hook `artist-mode-init-hook' is called.
!  When quitting artist-mode, the hook `artist-mode-exit-hook' is called.
  
  
  Keymap summary
  
  \\{artist-mode-map}"
!   (interactive)
!   (if (setq artist-mode
!           (if (null state) (not artist-mode)
!             (> (prefix-numeric-value state) 0)))
!       (artist-mode-init)
!     (artist-mode-exit)))
! 
! ;; insert our minor mode string
! (or (assq 'artist-mode minor-mode-alist)
!     (setq minor-mode-alist
!         (cons '(artist-mode artist-mode-name)
!               minor-mode-alist)))
! 
! ;; insert our minor mode keymap
! (or (assq 'artist-mode minor-mode-map-alist)
!     (setq minor-mode-map-alist
!         (cons (cons 'artist-mode artist-mode-map)
!               minor-mode-map-alist)))
! 
! 
! ;; Init and exit
! (defun artist-mode-init ()
!   "Init Artist mode.  This will call the hook `artist-mode-init-hook'."
!   ;; Set up a conversion table for mapping tabs and new-lines to spaces.
!   ;; the last case, 0, is for the last position in buffer/region, where
!   ;; the `following-char' function returns 0.
!   (let ((i 0))
!     (while (< i 256)
!       (aset artist-replacement-table i i)
!       (setq i (1+ i))))
!   (aset artist-replacement-table ?\n ?\s)
!   (aset artist-replacement-table ?\t ?\s)
!   (aset artist-replacement-table 0 ?\s)
!   ;; More setup
!   (make-local-variable 'artist-key-is-drawing)
!   (make-local-variable 'artist-key-endpoint1)
!   (make-local-variable 'artist-key-poly-point-list)
!   (make-local-variable 'artist-key-shape)
!   (make-local-variable 'artist-key-draw-how)
!   (make-local-variable 'artist-popup-menu-table)
!   (make-local-variable 'artist-key-compl-table)
!   (make-local-variable 'artist-prev-next-op-alist)
!   (make-local-variable 'artist-rb-save-data)
!   (make-local-variable 'artist-arrow-point-1)
!   (make-local-variable 'artist-arrow-point-2)
!   (setq artist-key-is-drawing nil)
!   (setq artist-key-endpoint1 nil)
!   (setq artist-key-poly-point-list nil)
!   (setq artist-key-shape nil)
!   (setq artist-popup-menu-table (artist-compute-popup-menu-table artist-mt))
!   (setq artist-key-compl-table (artist-compute-key-compl-table artist-mt))
!   (setq artist-prev-next-op-alist
!       (artist-make-prev-next-op-alist artist-key-compl-table))
!   (setq artist-rb-save-data (make-vector 7 0))
!   (setq artist-arrow-point-1 nil)
!   (setq artist-arrow-point-2 nil)
!   (make-local-variable 'next-line-add-newlines)
!   (setq next-line-add-newlines t)
!   (setq artist-key-draw-how
!       (artist-go-get-draw-how-from-symbol artist-curr-go))
!   (if (and artist-picture-compatibility (not (eq major-mode 'picture-mode)))
!       (progn
!       (picture-mode)
!       (message "")))
!   (run-hooks 'artist-mode-init-hook)
!   (artist-mode-line-show-curr-operation artist-key-is-drawing))
! 
! (defun artist-mode-exit ()
!   "Exit Artist mode.  This will call the hook `artist-mode-exit-hook'."
!   (if (and artist-picture-compatibility (eq major-mode 'picture-mode))
!       (picture-mode-exit))
!   (kill-local-variable 'next-line-add-newlines)
!   (run-hooks 'artist-mode-exit-hook))
  
  (defun artist-mode-off ()
    "Turn Artist mode off."
--- 1324,1438 ----
  
  Hooks
  
! Turning the mode on or off runs `artist-mode-hook'.
  
  
  Keymap summary
  
  \\{artist-mode-map}"
!   :init-value nil   :group 'artist :lighter " Artist"
!   :keymap
!   '(([down-mouse-1]   .       artist-down-mouse-1)
!     ([S-down-mouse-1] .       artist-down-mouse-1)
!     ([down-mouse-2]   .       artist-mouse-choose-operation)
!     ([S-down-mouse-2] .       artist-mouse-choose-operation)
!     ([down-mouse-3]   .       artist-down-mouse-3)
!     ([S-down-mouse-3] .       artist-down-mouse-3)
!     ([C-mouse-4]      .       artist-select-prev-op-in-list)
!     ([C-mouse-5]      .       artist-select-next-op-in-list)
!     ("\r"             .       artist-key-set-point) ; return
!     ([up]             .       artist-previous-line)
!     ("\C-p"           .       artist-previous-line)
!     ([down]           .       artist-next-line)
!     ("\C-n"           .       artist-next-line)
!     ([left]           .       artist-backward-char)
!     ("\C-b"           .       artist-backward-char)
!     ([right]          .       artist-forward-char)
!     ("\C-f"           .       artist-forward-char)
!     ("<"              .       artist-toggle-first-arrow)
!     (">"              .       artist-toggle-second-arrow)
!     ("\C-c\C-a\C-e"   .       artist-select-erase-char)
!     ("\C-c\C-a\C-f"   .       artist-select-fill-char)
!     ("\C-c\C-a\C-l"   .       artist-select-line-char)
!     ("\C-c\C-a\C-o"   .       artist-select-operation)
!     ("\C-c\C-a\C-r"   .       artist-toggle-rubber-banding)
!     ("\C-c\C-a\C-t"   .       artist-toggle-trim-line-endings)
!     ("\C-c\C-a\C-s"   .       artist-toggle-borderless-shapes)
!     ("\C-c\C-c"               .       artist-mode-off)
!     ("\C-c\C-al"      .       artist-select-op-line)
!     ("\C-c\C-aL"      .       artist-select-op-straight-line)
!     ("\C-c\C-ar"      .       artist-select-op-rectangle)
!     ("\C-c\C-aR"      .       artist-select-op-square)
!     ("\C-c\C-as"      .       artist-select-op-square)
!     ("\C-c\C-ap"      .       artist-select-op-poly-line)
!     ("\C-c\C-aP"      .       artist-select-op-straight-poly-line)
!     ("\C-c\C-ae"      .       artist-select-op-ellipse)
!     ("\C-c\C-ac"      .       artist-select-op-circle)
!     ("\C-c\C-at"      .       artist-select-op-text-see-thru)
!     ("\C-c\C-aT"      .       artist-select-op-text-overwrite)
!     ("\C-c\C-aS"      .       artist-select-op-spray-can)
!     ("\C-c\C-az"      .       artist-select-op-spray-set-size)
!     ("\C-c\C-a\C-d"   .       artist-select-op-erase-char)
!     ("\C-c\C-aE"      .       artist-select-op-erase-rectangle)
!     ("\C-c\C-av"      .       artist-select-op-vaporize-line)
!     ("\C-c\C-aV"      .       artist-select-op-vaporize-lines)
!     ("\C-c\C-a\C-k"   .       artist-select-op-cut-rectangle)
!     ("\C-c\C-a\M-w"   .       artist-select-op-copy-rectangle)
!     ("\C-c\C-a\C-y"   .       artist-select-op-paste)
!     ("\C-c\C-af"      .       artist-select-op-flood-fill)
!     ("\C-c\C-a\C-b"   .       artist-submit-bug-report)
!     ([menu-bar artist]        .       artist-menu-map))
!   (cond ((null artist-mode)
!        ;; Turn mode off
!        (if (and artist-picture-compatibility (eq major-mode 'picture-mode))
!            (picture-mode-exit))
!        (kill-local-variable 'next-line-add-newlines))
!       
!       (t
!        ;; Turn mode on
!        ;; Set up a conversion table for mapping tabs and new-lines to spaces.
!        ;; the last case, 0, is for the last position in buffer/region, where
!        ;; the `following-char' function returns 0.
!        (let ((i 0))
!          (while (< i 256)
!            (aset artist-replacement-table i i)
!            (setq i (1+ i))))
!        (aset artist-replacement-table ?\n ?\s)
!        (aset artist-replacement-table ?\t ?\s)
!        (aset artist-replacement-table 0 ?\s)
!        ;; More setup
!        (make-local-variable 'artist-key-is-drawing)
!        (make-local-variable 'artist-key-endpoint1)
!        (make-local-variable 'artist-key-poly-point-list)
!        (make-local-variable 'artist-key-shape)
!        (make-local-variable 'artist-key-draw-how)
!        (make-local-variable 'artist-popup-menu-table)
!        (make-local-variable 'artist-key-compl-table)
!        (make-local-variable 'artist-prev-next-op-alist)
!        (make-local-variable 'artist-rb-save-data)
!        (make-local-variable 'artist-arrow-point-1)
!        (make-local-variable 'artist-arrow-point-2)
!        (setq artist-key-is-drawing nil)
!        (setq artist-key-endpoint1 nil)
!        (setq artist-key-poly-point-list nil)
!        (setq artist-key-shape nil)
!        (setq artist-popup-menu-table (artist-compute-popup-menu-table 
artist-mt))
!        (setq artist-key-compl-table (artist-compute-key-compl-table 
artist-mt))
!        (setq artist-prev-next-op-alist
!              (artist-make-prev-next-op-alist artist-key-compl-table))
!        (setq artist-rb-save-data (make-vector 7 0))
!        (setq artist-arrow-point-1 nil)
!        (setq artist-arrow-point-2 nil)
!        (make-local-variable 'next-line-add-newlines)
!        (setq next-line-add-newlines t)
!        (setq artist-key-draw-how
!              (artist-go-get-draw-how-from-symbol artist-curr-go))
!        (if (and artist-picture-compatibility (not (eq major-mode 
'picture-mode)))
!            (progn
!              (picture-mode)
!              (message "")))
!        (artist-mode-line-show-curr-operation artist-key-is-drawing))))
! 
  
  (defun artist-mode-off ()
    "Turn Artist mode off."
***************
*** 1484,1490 ****
  
  (defun artist-mode-line-show-curr-operation (is-drawing)
    "Show current operation in mode-line.  If IS-DRAWING, show that."
!   (let ((mtext (concat artist-mode-name "/"
                       (artist-go-get-mode-line-from-symbol artist-curr-go)
                       (if is-drawing "/*" ""))))
      (setcdr (assq 'artist-mode minor-mode-alist) (list mtext)))
--- 1450,1456 ----
  
  (defun artist-mode-line-show-curr-operation (is-drawing)
    "Show current operation in mode-line.  If IS-DRAWING, show that."
!   (let ((mtext (concat " Artist/"
                       (artist-go-get-mode-line-from-symbol artist-curr-go)
                       (if is-drawing "/*" ""))))
      (setcdr (assq 'artist-mode minor-mode-alist) (list mtext)))







reply via email to

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