       (message "Sorry, not enough space..."))))
 
 ;;; Ctrl-> to right-aligh the text after point
-(global-set-key [(control >)] 'bde-aligh-right-after-point)
-
+(global-set-key [(control >)] 'bde-aligh-right)
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; Insert redundant include guards

(global-set-key [(control c)(=)] 'bde-insert-define-class-header)
(global-set-key [(control c)(-)] 'bde-insert-declare-class-header)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; BDE's right style comments such as // RETURN or // LOCK

(defun bde-aligh-right-after-point ()
  "Set the right amount of spaces around the point so the text
  after point is right-aligned (for things such as // RETURN). It
  works even if point is in a C++ comment."


(define-key c-mode-base-map [(control c)(a)] 'bde-align-functions-arguments)

(defun bde-align-funcall ()
  "Assuming the cursor is within the list of arguments of a
  function call, align the arguments. It puts one argument per
  line and aligns to the right"
  (interactive)
  ;; Get a list of the arguments. Note that the external parentheses are included
  (let ((arglist (thing-at-point 'list)))
    (when (pg/string-starts-with arglist "(")
      (setq arglist (substring arglist 1)))
    (when (pg/string-ends-with arglist ")")
      (setq arglist (substring arglist 0 (1- (length arglist)))))
    (let ((args (split-string arglist ","))
          (parsed-args ()))
      (dolist (arg args)
        (let ((parsed-arg (pg/string-trim (if (pg/string-starts-with arg "\n")
                                              (substring arg 1)
                                            arg))))
          (setq parsed-args (cons parsed-arg parsed-args))))
      (setq parsed-args (reverse parsed-args))
      ;; Cut the argument list and edit it into a temporary buffer
      (backward-up-list)
      (push-mark)
      (forward-list)
      (kill-region (region-beginning) (region-end))
      (insert
       (with-temp-buffer
         (insert "(")
         (let ((i 1))
           (dolist (arg parsed-args)
             (insert arg)
             (unless (>= i (length parsed-args))
               (insert ",")
               (newline))
             (incf i)))
         (insert ")")
         (buffer-string)))
      ;; Reindent
      (push-mark)
      (backward-list)
      (indent-region (region-beginning) (region-end))
      ;; If some lines exceed the dreadful 79th column, insert a new line before
      ;; the first line and reindent, with longest line to the right edge
      (save-excursion
        (let ((start-col (1+ (current-column)))
              (max-col (bde-max-column-in-region)))
          (when (> max-col 79)
            (backward-list)
            (forward-char)
            (newline)
            (backward-char 2)
            (push-mark)
            (forward-list)
            (let ((longest-length (- max-col start-col)))
              (if (<= longest-length 79)
                  (indent-region (region-beginning) (region-end)
                                 (- 79 longest-length))
                ;; We cannot indent correctly, some lines are too long
                (indent-region (region-beginning) (region-end))
                (message "Longest line is %d chars" longest-length)))))))))

(define-key c-mode-base-map [(control c)(f)] 'bde-align-funcall)

;;; End of file
(provide 'init-bde-style)
