diff --git a/.emacs.d/functions.el b/.emacs.d/functions.el index 6526825f..c1b08725 100644 --- a/.emacs.d/functions.el +++ b/.emacs.d/functions.el @@ -85,6 +85,45 @@ there's a region, all lines that region covers will be duplicated." (error (message "Invalid expression") (insert (current-kill 0))))) +;; Fix forward-page. Previously, when the point was at the end of the page, +;; going forward would skip 1 page. Changed: +;; +;; (if (bolp) (forward-char 1)) +;; +;; to +;; +;; (if (string= page-delimiter "") +;; +;; I do not know why the (bolp) condition was used since it does not match the +;; above comment. TODO: report this fix! +(defun forward-page (&optional count) + "Move forward to page boundary. With arg, repeat, or go back if negative. +A page boundary is any line whose beginning matches the regexp +`page-delimiter'." + (interactive "p") + (or count (setq count 1)) + (while (and (> count 0) (not (eobp))) + ;; In case the page-delimiter matches the null string, + ;; don't find a match without moving. + (if (string= page-delimiter "") (forward-char 1)) + (if (re-search-forward page-delimiter nil t) + nilp + (goto-char (point-max))) + (setq count (1- count))) + (while (and (< count 0) (not (bobp))) + ;; In case the page-delimiter matches the null string, + ;; don't find a match without moving. + (and (save-excursion (re-search-backward page-delimiter nil t)) + (= (match-end 0) (point)) + (goto-char (match-beginning 0))) + (forward-char -1) + (if (re-search-backward page-delimiter nil t) + ;; We found one--move to the end of it. + (goto-char (match-end 0)) + ;; We found nothing--go to beg of buffer. + (goto-char (point-min))) + (setq count (1+ count)))) + (defun get-closest-pathname (&optional file) "Get pathname of the first instance of FILE towards root. This may not do the correct thing in presence of links. If it @@ -334,7 +373,7 @@ It only works for frames with exactly two windows." (set-window-buffer (next-window) next-win-buffer) (select-window first-win) (if this-win-2nd (other-window 1)))))) -(define-key my-keys-minor-mode-map [(control c) (|)] 'toggle-window-split) +(define-key my-keys-minor-mode-map [(control x) (|)] 'toggle-window-split) (defun toggle-word-delim () "Make underscore part of the word syntax or not. diff --git a/.emacs.d/main.el b/.emacs.d/main.el index 478deed3..5e9df152 100644 --- a/.emacs.d/main.el +++ b/.emacs.d/main.el @@ -46,6 +46,7 @@ ;; Allow some protected functions. (put 'upcase-region 'disabled nil) (put 'downcase-region 'disabled nil) +(put 'narrow-to-page 'disabled nil) ;; Print column number in mode line. (column-number-mode 1) @@ -71,6 +72,10 @@ (condition-case nil (scroll-down) (beginning-of-buffer (goto-char (point-min))))))) +;; TODO: display page number in mode line with `what-page'. +(define-key my-keys-minor-mode-map (kbd "C-x M-n") (lambda () (interactive) (narrow-to-page 1))) +(define-key my-keys-minor-mode-map (kbd "C-x M-p") (lambda () (interactive) (narrow-to-page -1))) + ;; Line numbers ;; TODO: This mode is slow on big files when using beginning-of-buffer binding. (add-hook 'find-file-hook (lambda () (linum-mode 1))) @@ -87,6 +92,9 @@ ;; Line by line scrolling (setq scroll-step 1) +;; Useful of autofill. +(setq sentence-end-double-space nil) + ;; Highlight selections -- not activated by default on old Emacs. (transient-mark-mode 1) diff --git a/.emacs.d/mode-cc.el b/.emacs.d/mode-cc.el index 1f1f3f8a..1db101ed 100644 --- a/.emacs.d/mode-cc.el +++ b/.emacs.d/mode-cc.el @@ -53,6 +53,7 @@ restored." ;;============================================================================== (setq-default c-basic-offset 4) +(c-set-offset 'case-label '+) (mapcar (lambda (mode-hook)