Function: delete-forward-char

delete-forward-char is an interactive and byte-compiled function defined in simple.el.gz.

Signature

(delete-forward-char N &optional KILLFLAG)

Documentation

Delete the following N characters (previous if N is negative).

If Transient Mark mode is enabled, the mark is active, and N is 1, delete the text in the region and deactivate the mark instead. To disable this, set variable delete-active-region(var)/delete-active-region(fun) to nil.

If N is positive, characters composed into a single grapheme cluster count as a single character and are deleted together. Thus,
"\\[universal-argument] 2 \\[delete-forward-char]" when two grapheme clusters follow point will
delete the characters composed into both of the grapheme clusters.

Optional second arg KILLFLAG non-nil means to kill (save in kill ring) instead of delete. If called interactively, a numeric prefix argument specifies N, and KILLFLAG is also set if a prefix argument is used.

When killing, the killed text is filtered by filter-buffer-substring before it is saved in the kill ring, so the actual saved text might be different from what was killed.

Probably introduced at or before Emacs version 24.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/simple.el.gz
(defun delete-forward-char (n &optional killflag)
  "Delete the following N characters (previous if N is negative).
If Transient Mark mode is enabled, the mark is active, and N is 1,
delete the text in the region and deactivate the mark instead.
To disable this, set variable `delete-active-region' to nil.

If N is positive, characters composed into a single grapheme cluster
count as a single character and are deleted together.  Thus,
\"\\[universal-argument] 2 \\[delete-forward-char]\" when two grapheme clusters follow point will
delete the characters composed into both of the grapheme clusters.

Optional second arg KILLFLAG non-nil means to kill (save in kill
ring) instead of delete.  If called interactively, a numeric
prefix argument specifies N, and KILLFLAG is also set if a prefix
argument is used.

When killing, the killed text is filtered by
`filter-buffer-substring' before it is saved in the kill ring, so
the actual saved text might be different from what was killed."
  (declare (interactive-only delete-char))
  (interactive "p\nP")
  (unless (integerp n)
    (signal 'wrong-type-argument (list 'integerp n)))
  (cond ((and (use-region-p)
	      delete-active-region
	      (= n 1))
	 ;; If a region is active, kill or delete it.
	 (if (eq delete-active-region 'kill)
	     (kill-region (region-beginning) (region-end) 'region)
	   (funcall region-extract-function 'delete-only)))

	;; For forward deletion, treat composed characters as a single
	;; character to delete.
        ((>= n 1)
         (let ((pos (point))
               start cmp)
           (setq start pos)
           (while (> n 0)
             ;; 'find-composition' will return (FROM TO ....) or nil.
             (setq cmp (find-composition pos))
             (setq pos
                   (if cmp
                       (let ((from (car cmp))
                             (to (cadr cmp)))
                         (cond
                          ((and (= (length cmp) 3) ; static composition
                                (booleanp (nth 2 cmp)))
                           to)
                          ;; TO can be at POS, in which case we want
                          ;; to make sure we advance at least by 1
                          ;; character.
                          ((<= to pos)
                           (1+ pos))
                          (t
                           (lgstring-glyph-boundary (nth 2 cmp)
                                                    from (1+ pos)))))
                     (1+ pos)))
             (setq n (1- n)))
           (delete-char (- pos start) killflag)))

	;; Otherwise, do simple deletion.
	(t (delete-char n killflag))))