emacs external veiwer in my way

Posted on 2006-07-18
Last Modified: 2013-12-16

I have a problem opening a .cpp file with emacs
using debian testing and emacs21 21.4a-3
it does not open it. I need emcs to open it with its c++ mode and the
extra info I provide in .emacs

ctl-xf which does find/create a file then I type test.cpp then I get
this in the echo area
File is opened with an external viewer. See buffer *extview log* for
status messages.

in *extview log* I have
Opening file ~/test.cpp with handler: more '%s'
/home/fred/test.cpp: No such file or directory

Process extview-process finished


here is my .emacs
(load "~/.emacs-mc394")

;; makes relavent files executable
(add-hook 'after-save-hook

;; hitting shift-f8 will save the current buffer with permission 700
(defun chmod-save ()
  "Save and chmod 700 current buffer"
  (setq command (concat "chmod 700 " (buffer-file-name)))
  (message "%s " command)
  (shell-command command)
(global-set-key [(shift f8)] 'chmod-save)

;; opens a a file 'pdf' with xpdf and so on...
(require 'extview)
(push '("\\.pdf$" . "xpdf %s") extview-application-associations)
(push '("\\.py$" . nil) extview-application-associations)

(add-hook 'octave-mode-hook
          '(lambda ()
             (local-set-key [f9] 'octave-send-line)))

(add-hook 'c++-mode-hook
          '(lambda ()
             (turn-on-auto-fill) ;;Insert a newline if line gets to long.
             (c-toggle-auto-state 1) ;;Make ; and { and } and : all electric
             (c-set-style "mc394-style")))

(add-hook 'comint-output-filter-functions ;R bottom the prompt
        'comint-show-maximum-output nil t)

(global-font-lock-mode 1)

;; ;; Color highlighting stuff
;; (defvar xemacs-p
;;   (string-match "XEmacs" emacs-version))
;; (if (not xemacs-p)
;;     (progn
;;       (global-font-lock-mode t)
;; ; If using global-font-lock-mode, make control-L update colors
;;       (global-set-key "\C-l"
;;                       (function (lambda (arg) (interactive "P")
;;                                   (font-lock-fontify-block 100)
;;                                   (recenter arg))))))

;; this is needed for semantic and ECB to work correctly
(setq auto-mode-alist
  (append '(
    ("" . m4-mode)
    ("\\.m4\\'" . m4-mode)
    ("\\.am\\'" . makefile-mode)
    ("\\.cpp\\'" . c++-mode)
    ("\\.h$" . c++-mode)
    ("\\.py\\'" . python-mode))

(defun other-window-backward (&optional n)
    "Select Nth previous window"
    (interactive "P")
    (other-window (- (prefix-numeric-value n))))
(global-set-key "\C-x\C-p" 'other-window-backward)


(global-set-key [f6] 'setnu-mode)      ;set-number use twice after C-y
(global-set-key "\C-x\C-b" 'buffer-menu) ;binds the key C-x C-b to buffer-menu
(global-set-key [f7] (kbd "M-h M-;")) ;comment region
(global-set-key [f11] 'compile)         ;compiles a program
(global-set-key [f12] 'clipboard-kill-ring-save);copy marked region to Primary Selection, M-w copies to Clipboard, middle mouse botton to paste Primary, M-y pastes the clipboard contents

(global-set-key [f10]      'cut-ctrlM)   ; cut all ^M.
(defun cut-ctrlM ()  
  "Cut all visible ^M."
  (while (search-forward "\r" nil t)
    (replace-match "" nil t))

(global-set-key "\C-cw" "\M-b\C-@\M-f\M-w") ;copy word under point
(global-set-key "\C-cl" "\C-a\C-@\C-e\M-w") ;copy line under point
(global-set-key "\C-cs" "\M-a\C-@\M-e\M-w") ;copy sentence under point
(global-set-key "\C-cp" "\M-h\C-f\M-w")      ;copy paragraph under point

(setq ecb-auto-activate t)
(setq user-full-name "Gary Wessle")
(setq user-mail-address "")
(setq fill-column 70)                  ;Text lines limited to 70 chars
(setq make-backup-files nil)           ;don't make backup files
(setq kill-whole-line t)               ;killing line also deletes \n
(setq next-line-add-newlines nil)      ;down arror won't add \n at end
(setq line-number-mode t)              ;put line number in display
(setq column-number-mode t)            ;put column number in display
(setq inhibit-startup-message t)       ;disable startup message
(setq display-time-24hr-format t)      ;display 24h time formate
(setq transient-mark-mode t)           ;highlight marked
(setq default-major-mode 'text-mode)   ;new buffers are text mode
(add-hook 'text-mode-hook 'turn-on-auto-fill) ;line limit in text mode
(add-hook 'text-mode-hook 'flyspell-mode t) ; check spelling
(add-hook 'text-mode-hook 'text-mode-hook-identify)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on);ls not show ^[[0m
(display-time)                        ;time on line-mode
(tool-bar-mode 0)                  ; turn-off tool-bar
(menu-bar-mode 0)                  ; turn-off tool-bar
(scroll-bar-mode -1)                    ; turn-off scroll bar
(setq-default visible-bell t)          ; no beeps, flash on errors

;; don't show password
(add-hook 'comint-output-filter-functions

;; makes a vertical split along the horisontal line
(defun htv-horizontal-to-vertical ()
  (let ((one-buf (window-buffer (selected-window)))
        (buf-point (point)))
    (other-window 1)
    (switch-to-buffer one-buf)
    (goto-char buf-point)))

;; makes a vertical split along the horisontal line
(defun vth-vertical-to-horizontal ()
  (let ((one-buf (window-buffer (selected-window)))
        (buf-point (point)))
    (other-window 1)
    (switch-to-buffer one-buf)
    (goto-char buf-point)))

;; remove comments lines from region
(defun nea-kill-all-comments-in-region (begin end)
       "Kill all comments in region."
       (interactive "r")
       (goto-char begin)
       (kill-comment (count-lines begin end))))

;; remove comments lines from buffer
(defun nea-kill-all-comments-in-buffer ()
       "Kill all comments in buffer."
      (count-lines (point-min) (point-max)))))    

(add-hook 'c++-mode-hook 'setnu-mode)   ;line numbers
(add-hook 'c++-mode-hook 'bar-cursor-mode) ;cursor to a bar
(add-hook 'c++-mode-hook 'show-paren-mode) ;marrying brackets show

(require 'xcscope) ;"$man cscope" for more info
  ;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
  ;; Your init file should contain only one such instance.
 '(ecb-methods-nodes-expand-spec (quote all))
 '(ecb-options-version "2.27"))

  ;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
  ;; Your init file should contain only one such instance.
 '(default ((t (:stipple nil :background "black" :foreground "white" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 123 :width normal :family "adobe-courier"))))
 '(comint-highlight-input ((t (:background "black" :weight bold))))
 '(cursor ((t (:background "yellow"))))
 '(mouse ((t (:background "yellow")))))

(put 'erase-buffer 'disabled nil)


and my .emacs-mc394
;; Modified by Mike Hvidsten from MC38J emacs file
;;  Feb. 4, 2004

(c-add-style "mc394-style"
               (c-basic-offset . 3)      ; In general, indent 3 spaces
                (defun-open after))      ; brace that opens a function definition
               (c-cleanup-list brace-else-brace
                ; These determine whether a newline appears before
                ; and/or after a brace in various situations.
                (block-open after)       ; statement block open brace
                (defun-open after)       ; brace that opens a function definition
                (substatement-open after); the brace that opens a substatement block
                (block-close . c-snug-do-while))
                (access-label after)) ; Newline after protected: or private:
               (c-hungry-delete-key t))) ; delete black space all at once

;; Variable should be t if we are running xemacs.
(defvar xemacs-p
  (string-match "XEmacs" emacs-version))

(if (not xemacs-p)
      (global-font-lock-mode t)
       ; If using global-font-lock-mode, make control-L update colors
      (global-set-key "\C-l"
                      (function (lambda (arg) (interactive "P")
                                  (font-lock-fontify-block 100)
                                  (recenter arg))))))
(setq auto-mode-alist (append '(("\\.h$" . c++-mode)) auto-mode-alist))
Question by:samj
  • 6
  • 2
LVL 22

Expert Comment

ID: 17131677
You have a emacs lisp file somewhere called:


In it, there is probably a line which states that cpp files should eb opened with /home/fred/test.cpp

Delete the line similar to:

'(("\\.cpp$" . "/home/fred/test.cpp"))

(   (()
(`-' _\
 ''  ''

Author Comment

ID: 17131757
there is no mention of cpp at all

here is the file extview.el

;;; extview.el --- open files with external viewer

;; Copyright (C) 2006 Tamas Patrovics

;; $Date: 2006-04-04 12:58:37 $

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;; Load the library and try opening a file which has an associated
;; application in `extview-application-associations' or in mailcap.
;; `extview-application-associations' can be used to override mailcap
;; handlers:
;;   (require 'extview)
;;   (push '("\\.pdf$" . "acroread %s") extview-application-associations)
;;   (push '("\\.py$" . nil) extview-application-associations)
;;   (push '("\\.html$" . ask) extview-application-associations)

;;; Code:

(eval-when-compile (require 'cl))
(require 'mailcap)


(defvar extview-application-associations nil
  "List of (REGEXP . HANDLER) descriptors which are tested for the
file name to be opened. The first matching handler is used to open
the file. If no handler matches then an attempt is made to use
mailcap to open the file.

If no handler is found normal `find-file' is executed.

If HANDLER is nil then the file is opened normally regardless if
it has a mailcap entry.

If HANDLER is the symbol `ask' then the user has to decide whether the
file is to be opened in emacs or with an external viewer.

This variable is normally used to override mailcap handlers.")

(defadvice find-file (around extview-find-file
                             (filename &optional wildcards) activate)
  "Around advice for find-file which checks if the file should be
opened with an external viewer instead of Emacs."
  (interactive "FFind file: \np")
  ;; check `extview-application-associations' first, since it has
  ;; priority
  (let ((handler (some (lambda (descriptor)
                         (if (string-match (car descriptor) filename)
    (if (and handler
             (not (and (eq 'ask (cdr handler))
                       (y-or-n-p "Open with external viewer? "))))
        (if (eq (cdr handler) 'ask)     ; open with emacs
            (setq handler nil)
          (setq handler (cdr handler)))

      ;; check if there is an appropriate mailcap entry
      (let* ((ext (file-name-extension filename))
             (mime (if ext
                       (mailcap-extension-to-mime ext))))
        (if mime
            (setq handler (mailcap-mime-info mime)))

        ;; only string handlers are considered, since we're interested
        ;; in external viewers, not emacs functions
        (unless (stringp handler)
          (setq handler nil))))

    ;; call the handler if found
    (if handler
        (let* ((logbuffer "*extview log*")
               (components (split-string handler))
               ;; hopefully the first component is always the
               ;; application name
               (app (car components))
               ;; substitute file name for %s args
               (args (mapcar (lambda (arg)
                               (if (or (equal "%s" arg)
                                       (equal "'%s'" arg))
                                   (expand-file-name filename)
                             (cdr components))))
          (get-buffer-create logbuffer)
          (with-current-buffer logbuffer
            (goto-char (point-max))
            (insert (format "Opening file %s with handler: %s"
                            filename handler)

          (apply 'start-process "extview-process" logbuffer app args)          

          (message (concat "File is opened with an external viewer. "
                           "See buffer %s for status messages.")

(provide 'extview)
;;; extview.el ends here


Author Comment

ID: 17133937
this might help
I can find/open my.cpp if I
$gksu emacs my.cpp
type in the root password

it then opens and in the mode it says
-1:-- my.cpp  (C++ Abbrev)--L1--All--
LVL 22

Expert Comment

ID: 17134040
I'm not an emacs specialist I'm afraid - I only use it occassionally.

The fact that doing it with a different permission works implies that there is perhaps a local 'hidden' '.' configuration file. By 'su' ing you are using a different configuration (roots).

Not sure what the . file would be called (but I presume that it is in addition to the .emacs file), but that's what I'd be looking for. Sorry I can't be more helpful:(

(   (()
(`-' _\
 ''  ''
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.


Author Comment

ID: 17136296
I deleted every thing in .emacs reloaded the file and the problem is
still there.  
it is only when I delete .emacs from my home dir that the problem does
not duplicate.


Author Comment

ID: 17136314
it is only when I delete .emcas from my hode dir and restart emacs that the problem does not duplicate.

Author Comment

ID: 17136763
ok, I fix the problem at least for just now.
I commented out the section

;; ;; opens a a file 'pdf' with xpdf and so on...
;; (require 'extview)
;; (push '("\\.pdf$" . "xpdf %s") extview-application-associations)
;; (push '("\\.py$" . nil) extview-application-associations)
restarted emacs and I am now cpp compliant. no clue as to how to fix the problem so that I can have the functionality provided by the section above.

Author Comment

ID: 17150755
if a permenent solution is found, the points will be awareded.

Accepted Solution

GhostMod earned 0 total points
ID: 17168453
Closed, 250 points refunded.

Community Support Moderator

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now