Hungry delete

Bug #328853 reported by Rbreu
2
Affects Status Importance Assigned to Milestone
python-mode.el
Fix Released
Medium
Andreas Roehler

Bug Description

I really love the hungry-delete feature of Emacs'
c-mode. It would be great to have hungry-delete for
python-mode as well.

[http://sourceforge.net/tracker/index.php?func=detail&aid=1566228&group_id=86916&atid=581352]

Related branches

Changed in python-mode:
assignee: nobody → Andreas Roehler (a-roehler)
Changed in python-mode:
status: New → In Progress
Revision history for this message
Andreas Roehler (a-roehler) wrote :

Hi,

applied the following at myrkwid-branch, which should enable the feature.

Thanks for the request

Andreas

;;;;;;;;;;;;

=== modified file 'python-mode.el'
--- python-mode.el 2011-04-04 12:36:19 +0000
+++ python-mode.el 2011-04-05 08:41:49 +0000
@@ -939,6 +939,10 @@
     ;; who cares? XEmacs 20 does the right thing with these too).
     (define-key py-mode-map [delete] 'py-electric-delete)
     (define-key py-mode-map [backspace] 'py-electric-backspace))
+ ;; lp:328853
+ (define-key py-mode-map [?\C-c ?\d] 'py-hungry-delete-backwards)
+ (define-key py-mode-map [?\C-c ?\C-\d] 'py-hungry-delete-backwards)
+ (define-key py-mode-map [?\C-c delete] 'py-hungry-delete-forward)
   ;; Separate M-BS from C-M-h. The former should remain
   ;; backward-kill-word.
   (define-key py-mode-map [(control meta h)] 'py-mark-def-or-class)
@@ -2674,6 +2678,8 @@

 ;; Functions for moving point
+(defalias 'py-hungry-delete-forward 'c-hungry-delete-forward)
+(defalias 'py-hungry-delete-backwards 'c-hungry-delete-backwards)

Changed in python-mode:
status: In Progress → Fix Committed
Revision history for this message
Barry Warsaw (barry) wrote :

FWIW, I once implemented hungry-delete for Python mode, but then disabled it. Because Python is so dependent on indentation, I found hungry-delete to be more of a pain than a benefit when editing Python code.

Revision history for this message
Andreas Roehler (a-roehler) wrote :

Hi Barry,

may revert that patch.

OTOH it's nothing more than keys and alias provided.

Certainly it should not be pressed per chance...

Andreas

Revision history for this message
Andreas Roehler (a-roehler) wrote : Re: [Bug 328853] Re: Hungry delete

Am 05.04.2011 17:50, schrieb Barry Warsaw:
> FWIW, I once implemented hungry-delete for Python mode, but then
> disabled it. Because Python is so dependent on indentation, I found
> hungry-delete to be more of a pain than a benefit when editing Python
> code.
>

Ah, seeing a bit late you commented that out already...

Sorry being that autistic :-)

Andreas

Revision history for this message
Barry Warsaw (barry) wrote :

No worries. :) The other thing to be concerned with your patch is that it creates an explicit dependency between python-mode and c-mode. I'm not sure that's a good idea!

Revision history for this message
Andreas Roehler (a-roehler) wrote :

Am 05.04.2011 21:00, schrieb Barry Warsaw:
> No worries. :) The other thing to be concerned with your patch is that
> it creates an explicit dependency between python-mode and c-mode. I'm
> not sure that's a good idea!
>

Have pondered that question too and made the fallbacks below.
Finally came to the conclusion rather to keep the code slim and rely on
the good old c-mode features.

If it breaks, we can replace it still.

If you want to have the stuff now, I'll paste it in.

Cheers

Andreas

;;;;;;;;;;;;;;

(defun hungry-delete-backward (&optional killp)
   "Delete backward all whitespaces including tabs.

If KILLP is non-nil, deleted string is stored into the kill-ring."
   (interactive "*P")
   (let ((backward-delete-char-untabify-method 'hungry))
     (backward-delete-char-untabify 1 killp)))

(defun hungry-delete-backward-all (&optional killp)
   "Delete backward all whitespaces, including tabs and newlines.

If KILLP is non-nil, deleted string is stored into the kill-ring."
   (interactive "*P")
   (let ((backward-delete-char-untabify-method 'all))
     (backward-delete-char-untabify 1 killp)))

(defun hungry-delete-forward (&optional killp)
   "Delete forward all whitespaces including tabs.

If KILLP is non-nil, deleted string is stored into the kill-ring."
   (interactive "*P")
   (let ((orig (point)))
     (or (< 0 (skip-chars-forward " \t"))
         (forward-char 1))
     (when killp
       (kill-new (buffer-substring-no-properties orig (point))))
     (delete-region orig (point))))

(defun hungry-delete-forward-all (&optional killp)
   "Delete forward all whitespaces including tabs and newlines.

If KILLP is non-nil, deleted string is stored into the kill-ring."
   (interactive "*P")
   (let ((orig (point)))
     (or (< 0 (skip-chars-forward " \t\r\n"))
         (forward-char 1))
     (when killp
       (kill-new (buffer-substring-no-properties orig (point))))
     (delete-region orig (point))))

Changed in python-mode:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.