Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-18-2009, 03:04 PM   #1
Registered: Oct 2004
Location: Cheshire, England
Distribution: Debian Stable
Posts: 269

Rep: Reputation: 39
weird numbers and format in compile output in Emacs

New to Emacs and C++, I wrote a bit of code and did the meta -x compile g++ thing and got a messed up output (see attached).

Any idea how to clean it up?

Oh, and if it helps this is the .emacs I'm using (most of it is a file off the web:-

;; -*-Emacs-Lisp-*-
;; This file is designed to be re-evaled; use the variable first-time
;; to avoid any problems with this.
(defvar first-time t
"Flag signifying this is the first time that .emacs has been evaled")

(setq inhibit-splash-screen t) ;; no splash screen)

;; Meta
(global-set-key "\M- " 'set-mark-command)
(global-set-key "\M-\C-h" 'backward-kill-word)
(global-set-key "\M-\C-r" 'query-replace)
(global-set-key "\M-r" 'replace-string)
(global-set-key "\M-g" 'goto-line)
(global-set-key "\M-h" 'help-command)

;; Function keys
(global-set-key [f1] 'kill-region)
(global-set-key [f2] 'copy-region-as-kill)
(global-set-key [f3] 'yank)

(global-set-key [f4] 'advertised-undo)
(global-set-key [f5] 'eval-current-buffer)
(global-set-key [f6] 'buffer-menu)
(global-set-key [f7] 'other-window)
(global-set-key [f8] 'find-file)
(global-set-key [f9] 'save-buffer)
(global-set-key [f10] 'next-error)
(global-set-key [f11] 'compile)
(global-set-key [f12] 'grep)
(global-set-key [C-f1] 'compile)
(global-set-key [C-f2] 'grep)
(global-set-key [C-f3] 'next-error)
(global-set-key [C-f4] 'previous-error)
(global-set-key [C-f5] 'display-faces)
(global-set-key [C-f8] 'dired)
(global-set-key [C-f10] 'kill-compilation)

;; Set foreground and background
(set-foreground-color "#adff2f")
(set-background-color "black")

;; Mouse
(global-set-key [mouse-3] 'imenu)

;; Misc
(global-set-key [C-tab] "\C-q\t") ; Control tab quotes a tab.
(setq backup-by-copying-when-mismatch t)

;; Treat 'y' or <CR> as yes, 'n' as no.
(fset 'yes-or-no-p 'y-or-n-p)
(define-key query-replace-map [return] 'act)
(define-key query-replace-map [?\C-m] 'act)

;; Load packages
(require 'desktop)
(require 'tar-mode)

;; Pretty diff mode
(autoload 'ediff-buffers "ediff" "Intelligent Emacs interface to diff" t)
(autoload 'ediff-files "ediff" "Intelligent Emacs interface to diff" t)
(autoload 'ediff-files-remote "ediff"
"Intelligent Emacs interface to diff")

(if first-time
(setq auto-mode-alist
(append '(("\\.cpp$" . c++-mode)
("\\.hpp$" . c++-mode)
("\\.lsp$" . lisp-mode)
("\\.scm$" . scheme-mode)
("\\.pl$" . perl-mode)
) auto-mode-alist)))

(defface c-escape-char-face
'((((class color)) (:foreground "magenta")))
"highlight c escapes like in vim"
:group 'font-lock-faces)

(defface numeric-literals-face
'((((class color)) (:foreground "white")))
"highlight numbers in this face"
:group 'font-lock-faces)

(dolist (mode '(c-mode c++-mode))
mode '(("\\\\\\(?:[abfnrtv'\"?\\0]\\|x[a-fA-F]\\{2\\}\\|[0-7]\\{3\\}\\)"
0 'c-escape-char-face prepend)
0 'numeric-literals-face prepend))))

(set-face-foreground 'default "palegreen")
(set-face-foreground 'font-lock-variable-name-face "palegreen")
(set-face-foreground 'font-lock-function-name-face "palegreen")
(set-face-foreground 'font-lock-keyword-face "yellow")
(set-face-foreground 'font-lock-string-face "white")
(set-face-foreground 'font-lock-type-face "gray")

;; Auto font lock mode
(defvar font-lock-auto-mode-list
(list 'c-mode 'c++-mode 'c++-c-mode 'emacs-lisp-mode 'lisp-mode 'perl-mode 'scheme-mode)
"List of modes to always start in font-lock-mode")

(defvar font-lock-mode-keyword-alist
'((c++-c-mode . c-font-lock-keywords)
(perl-mode . perl-font-lock-keywords))
"Associations between modes and keywords")

(defun font-lock-auto-mode-select ()
"Automatically select font-lock-mode if the current major mode is in font-lock-auto-mode-list"
(if (memq major-mode font-lock-auto-mode-list)
(font-lock-mode t))

(global-set-key [M-f1] 'font-lock-fontify-buffer)

;; C++ and C mode...
(defun my-c++-mode-hook ()
(setq tab-width 4)
(define-key c++-mode-map "\C-m" 'reindent-then-newline-and-indent)
(define-key c++-mode-map "\C-ce" 'c-comment-edit)
(setq c++-auto-hungry-initial-state 'none)
(setq c++-delete-function 'backward-delete-char)
(setq c++-tab-always-indent t)
(setq c-indent-level 4)
(setq c-continued-statement-offset 4)
(setq c++-empty-arglist-indent 4))

(defun my-c-mode-hook ()
(setq tab-width 4)
(define-key c-mode-map "\C-m" 'reindent-then-newline-and-indent)
(define-key c-mode-map "\C-ce" 'c-comment-edit)
(setq c-auto-hungry-initial-state 'none)
(setq c-delete-function 'backward-delete-char)
(setq c-tab-always-indent t)
;; BSD-ish indentation style
(setq c-indent-level 4)
(setq c-continued-statement-offset 4)
(setq c-brace-offset -4)
(setq c-argdecl-indent 0)
(setq c-label-offset -4))

;; Emacs-Lisp mode...
(defun my-lisp-mode-hook ()
(define-key lisp-mode-map "\C-m" 'reindent-then-newline-and-indent)
(define-key lisp-mode-map "\C-i" 'lisp-indent-line)
(define-key lisp-mode-map "\C-j" 'eval-print-last-sexp))

;; Add all of the hooks...
(add-hook 'c++-mode-hook 'my-c++-mode-hook)
(add-hook 'c-mode-hook 'my-c-mode-hook)
(add-hook 'scheme-mode-hook 'my-scheme-mode-hook)
(add-hook 'emacs-lisp-mode-hook 'my-lisp-mode-hook)
(add-hook 'lisp-mode-hook 'my-lisp-mode-hook)
(add-hook 'perl-mode-hook 'my-perl-mode-hook)

;; Complement to next-error
(defun previous-error (n)
"Visit previous compilation error message and corresponding source code."
(interactive "p")
(next-error (- n)))

;; Misc...
(transient-mark-mode 1)
(setq mark-even-if-inactive t)
(setq visible-bell nil)
(setq next-line-add-newlines nil)
(setq compile-command "make")
(setq suggest-key-bindings nil)
(put 'eval-expression 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'set-goal-column 'disabled nil)
(if (>= emacs-major-version 21)
(setq show-trailing-whitespace t))

;; Elisp archive searching
(autoload 'format-lisp-code-directory "lispdir" nil t)
(autoload 'lisp-dir-apropos "lispdir" nil t)
(autoload 'lisp-dir-retrieve "lispdir" nil t)
(autoload 'lisp-dir-verify "lispdir" nil t)

;; Font lock mode
(defun my-make-face (face color &optional bold)
"Create a face from a color and optionally make it bold"
(make-face face)
(copy-face 'default face)
(set-face-foreground face color)
(if bold (make-face-bold face))

(if (eq window-system 'x)
(my-make-face 'blue "blue")
(my-make-face 'red "red")
(my-make-face 'green "dark green")
(setq font-lock-comment-face 'blue)
(setq font-lock-string-face 'bold)
(setq font-lock-type-face 'bold)
(setq font-lock-keyword-face 'bold)
(setq font-lock-function-name-face 'red)
(setq font-lock-doc-string-face 'green)
(add-hook 'find-file-hooks 'font-lock-auto-mode-select)

(setq baud-rate 1000000)
(global-set-key "\C-cmm" 'menu-bar-mode)
(global-set-key "\C-cms" 'scroll-bar-mode)
(global-set-key [backspace] 'backward-delete-char)
; (global-set-key [delete] 'delete-char)
(standard-display-european t)
(load-library "iso-transl")))

;; X11 or PC using direct screen writes
(if window-system
;; (global-set-key [M-f1] 'hilit-repaint-command)
;; (global-set-key [M-f2] [?\C-u M-f1])
(setq hilit-mode-enable-list
'(not text-mode c-mode c++-mode emacs-lisp-mode lisp-mode
hilit-auto-highlight nil
hilit-auto-rehighlight 'visible
hilit-inhibit-hooks nil
hilit-inhibit-rebinding t)
(require 'hilit19)
(require 'paren))
(setq baud-rate 2400) ; For slow serial connections

;; TTY type terminal
(if (and (not window-system)
(not (equal system-type 'ms-dos)))
(if first-time
(keyboard-translate ?\C-h ?\C-?)
(keyboard-translate ?\C-? ?\C-h)))))

;; Under UNIX
(if (not (equal system-type 'ms-dos))
(if first-time

;; Add any face changes here
(add-hook 'term-setup-hook 'my-term-setup-hook)
(defun my-term-setup-hook ()
(if (eq window-system 'pc)
;; (set-face-background 'default "red")

;; Restore the "desktop" - do this as late as possible
(if first-time

;; Indicate that this file has been read at least once
(setq first-time nil)

;; No need to debug anything now

(setq debug-on-error nil)

;; All done
(message "All done, %s%s" (user-login-name) ".")

(put 'upcase-region 'disabled nil)
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.

(require 'color-theme)
Attached Thumbnails
Click image for larger version

Name:	Screenshot-1.png
Views:	15
Size:	94.0 KB
ID:	327  
Old 03-18-2009, 04:50 PM   #2
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Ah, yeah. I've no idea why or who thought this would be cool, but on Ubuntu GCC produces output that uses the UTF-8 quote and unquote marks. Your Emacs buffer isn't using the right encoding so it displays the one glyph it knows how to render given it's byte value, and then displays two octets because it doesn't know what glyph to use for them. (This is pretty standard Emacs behaviour; if you open a binary file you'll see lots of them. It's useful. Of course hexl-mode is better for binary files but I digress.) I don't remember if I worked around it or not, I don't use Ubuntu at home but my Emacs does use UTF-8 encoding by default. I think nowadays the only thing you need to do is (set-language-environment "UTF-8"). There's all kinds of stuff you can do with fonts and stuff too, to use certain fonts for certain encodings and so forth. My .emacs file is on the web here: It's pretty nice and works for me, though it by no means as complicated as some people's that you'll find. :^)
Old 03-19-2009, 02:18 AM   #3
Registered: Oct 2004
Location: Cheshire, England
Distribution: Debian Stable
Posts: 269

Original Poster
Rep: Reputation: 39
Thanks for your help! worked like a charm.

Thanks again, now all I have to do is learn enough C++ to write my own version of Quake

By the way, seeing as you clearly have experience of Vim and Emacs (going off the link in your post) which would be your choice for C++ coding? I'm not trying to get the wars going here just asking for the opinion of somebody with more experience than I have. I was planning to use Emacs for email but I'm having a few problems getting it to play ball.

Last edited by blastradius; 03-19-2009 at 07:54 AM.
Old 03-19-2009, 11:02 AM   #4
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Certain things are obvious from my point-of-view: Lisp or LaTeX I'd use Emacs without a doubt. Other languages like Lua or HTML I use Vim because of better syntax support. I prefer the editing capabilities of Vim (almost everything can be done in a few keystrokes) so really I use Emacs when there are other forces pulling greatly in it's favor, which is usually a killer major mode. On Emacs: Lisp has SLIME, LaTeX has AUCTeX, JavaScript has Steve Yegge's js2-mode, and there's a very nice hex editor too (hexl-mode). But other than that I typically use Vim. In particular at work I write a lot of Java code and Emacs' Java mode sucks (people always talk about some Emacs Lisp code that acts like a Java IDE but it's a true pain to get working in my experience).

I think that contrary to popular opinion there is no one true editor and therefore it would be ideal to learn both and pick which one suits the current task. Of course, it's taken me years to build up the experience to be able to tell the difference solidly and have the expertise to use both with great effectiveness.

Using GNUS for email was always a so-so experience for me. It's a pretty great news reader, however. Over the few years I've switched to mutt instead for mail. Sylpheed is also quite nice.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
nasm assembler; output numbers? infinity42 Programming 4 05-26-2018 01:22 PM
Format numbers using bash? KClaisse Programming 21 03-30-2015 06:47 AM
More Emacs-help, interpret/compile from emacs? raskol Programming 2 04-19-2008 01:24 PM
Format large numbers with commas at every thousandth decimal spot helpmhost Linux - General 8 10-01-2007 11:54 AM
fstab file format - numbers at the end jjisnow Linux - Newbie 3 03-23-2004 06:54 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:16 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration